dongshou6041 2017-04-19 05:07
浏览 157
已采纳

为什么我刷新CAPTCHA在firefox中不起作用? [重复]

This question already has an answer here:

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);
        }
</div>
  • 写回答

1条回答 默认 最新

  • dongtu0088 2017-04-19 07:15
    关注

    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> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!