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 itest不允许查看成绩怎么办
  • ¥15 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏
  • ¥15 STM32串口接收问题