使用php和jquery动态更新验证码
如果您能就此提供任何建议,我将不胜感激。 需要动态更新php脚本生成的验证码图像, 单击“验证码刷新”时。 下面是我试图实现它的方式。不幸的是,这种方法只适用于Google Chrome, 其他浏览器似乎不理解这一点 HTML PHP打印图像:使用php和jquery动态更新验证码,php,jquery,captcha,Php,Jquery,Captcha,如果您能就此提供任何建议,我将不胜感激。 需要动态更新php脚本生成的验证码图像, 单击“验证码刷新”时。 下面是我试图实现它的方式。不幸的是,这种方法只适用于Google Chrome, 其他浏览器似乎不理解这一点 HTML PHP打印图像: header("Content-Type: image/jpeg"); ImageJpeg($captchaImage); <?php header("Content-Type: image/jpeg"); header("Cache-Contr
header("Content-Type: image/jpeg");
ImageJpeg($captchaImage);
<?php
header("Content-Type: image/jpeg");
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
// rest of your image generation code
方法如下:$('#someButton').click(function(){$('#someDiv').load('captcha.php');})代码>
建议在
它不起作用。
感谢您的关注。尝试使用更通用的语法:
$('.captcha_refresh').click(function () {
$('.captcha_image').attr('src', $(this).attr('href'));
return false;
});
尝试使用更通用的语法:
$('.captcha_refresh').click(function () {
$('.captcha_image').attr('src', $(this).attr('href'));
return false;
});
将随机查询字符串添加到图像源:
$('img.captcha_image').attr('src', $(this).attr('href') + '?rand=' + Math.random());
您还应随图像发送缓存控制
和过期
标题,并指示浏览器不应缓存图像:
header("Content-Type: image/jpeg");
ImageJpeg($captchaImage);
<?php
header("Content-Type: image/jpeg");
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
// rest of your image generation code
向图像源添加随机查询字符串:
$('img.captcha_image').attr('src', $(this).attr('href') + '?rand=' + Math.random());
您还应随图像发送缓存控制
和过期
标题,并指示浏览器不应缓存图像:
header("Content-Type: image/jpeg");
ImageJpeg($captchaImage);
<?php
header("Content-Type: image/jpeg");
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
// rest of your image generation code
thanx,它绝对有效。对不起,我没有足够的声望去投票,不客气。你应该能在几分钟内接受答案。thanx,它绝对有效。对不起,我没有足够的声望去投票,不客气。你应该能在几分钟内接受答案。