【问题标题】:why my refresh CAPTCHA doesn't work in firefox? [duplicate]为什么我的刷新验证码在 Firefox 中不起作用? [复制]
【发布时间】:2017-09-15 03:48:42
【问题描述】:

我将 smarty 与 codeigniter 一起使用。我的刷新验证码在 chrome 中可以正常工作并更改验证码的图片,但它在 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);
        }

【问题讨论】:

标签: javascript php codeigniter captcha


【解决方案1】:

img src属性是一样的,所以可能刷新不正确或者浏览器使用缓存(我不确定只有火狐不会刷新)。

我建议你添加一些参数来防止缓存,例如 url 的时间

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 2018-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-29
    • 2011-02-25
    相关资源
    最近更新 更多