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

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器