0

i use smarty with codeigniter. my refresh captcha work in chrome correctly and change picture of captcha but it doesn't work in firefox and my captcha doesn't change.

part of my view:

<script>
function refreshCaptcha() {
$("#captcha_code").attr('src','{$url}Login/captcha');
}
</script>   
</head>
  <form class="m-t" role="form" action="{$url}admin/Dashboard" 
   method="POST">
     <img id="captcha_code" src="{$url}Login/captcha" />
    <a name="submit"  class="btnRefresh" onClick="refreshCaptcha();">Refresh 
  Captcha</a>
  </form>

my controller:

   public function captcha()
   {        
    $image = @imagecreatetruecolor(120, 30) or die("Cannot Initialize new GD 
   image stream");
    $background = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
    imagefill($image, 0, 0, $background);
    $linecolor = imagecolorallocate($image, 0xCC, 0xCC, 0xCC);
    $textcolor = imagecolorallocate($image, 0x33, 0x33, 0x33);
    for($i=0; $i < 6; $i++)
    {  imagesetthickness($image, rand(1,3));
        imageline($image, 0, rand(0,30), 120, rand(0,30), $linecolor);}
    session_start();
    $digit = '';
    for($x = 15; $x <= 75; $x += 20)
    {   $digit .= ($num = rand(0, 9));          
        imagechar($image, rand(3, 5), $x, rand(2, 14), $num, $textcolor);
    $_SESSION['captcha_code'] = $digit;
    header('Content-type: image/png');
    imagepng($image);
    imagedestroy($image);
        }
Rosa
  • 3
  • 5
  • Look here: http://stackoverflow.com/questions/1077041/refresh-image-with-a-new-one-at-the-same-url – Lars Apr 19 '17 at 07:21

1 Answers1

1

The img src attribute is the same, so it may not refresh correctly or the browser using cache (I'm not sure that only Firefox won't refresh).

I recommend you to add some parameter to prevent cache, such as time to url

<script>
function refreshCaptcha() {
   $("#captcha_code").attr('src','{$url}Login/captcha?_t='+new Date().getTime());
}
</script> 
HeeMZa
  • 86
  • 2
  • 5