2017-04-19 68 views
0

我使用smarty和codeigniter。我的刷新驗證碼正確地在chrome中工作並更改了captcha的圖片,但它在firefox中不起作用,我的驗證碼不會更改。我的觀點的爲什麼我的刷新CAPTCHA在Firefox中不起作用?

部分:

<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> 

我的控制器:

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); 
     } 
+0

看:http://stackoverflow.com/questions/1077041/refresh-image-with-a-new -one-at-the-the-the-url – Lars

+0

非常感謝你 – Rosa

回答

1

的IMG SRC屬性是一樣的,所以它可能不正確刷新或使用緩存的瀏覽器(我不是確保只有Firefox不會刷新)。

我建議你添加一些參數,以防止緩存,如時間在這裏網址

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

非常感謝它的工作.... – Rosa

相關問題