Heim  >  Artikel  >  Backend-Entwicklung  >  firefox php 验证码图片 多次请求问题 待解决

firefox php 验证码图片 多次请求问题 待解决

WBOY
WBOYOriginal
2016-07-29 09:11:031179Durchsuche

??摘要:在使用GD库做验证码的过程中,使用firefox调试,发现浏览器显示的验证码图片与firebug响应的验证码图片不同,firebug响应的验证码图片的字符串与session里面存的字符串相同,网上查找以后,找到思路,有可能是firefox的浏览器显示的请求与firebug的请求不是一个请求,故做下面的验证,记录这个问题。

??为了更针对这个问题做出验证,将原代码进行了精简和修改,更适合于验证这个问题。好,先上代码。

<code><span><span><?php </span>
header(<span>"content-type:image/png"</span>);
session_start();
<span>if</span> (<span>isset</span>(<span>$_SESSION</span>[<span>'index'</span>])) {
    <span>$_SESSION</span>[<span>'index'</span>] += <span>1</span>;
}<span>else</span>{
    <span>$_SESSION</span>[<span>'index'</span>] = <span>1</span>;
}

<span>$width</span> = <span>80</span>;
<span>$height</span> = <span>20</span>;
<span>$vCodeString</span> = <span>""</span>;

<span>$vCodeString</span> = <span>"{$_SESSION['index']}"</span>;
<span>$_SESSION</span>[<span>'vcode'</span>] = <span>$vCodeString</span>;

<span>$image</span> = imagecreate(<span>$width</span>,<span>$height</span>);
<span>$background</span> = imagecolorallocate(<span>$image</span>,<span>255</span>,<span>255</span>,<span>255</span>);
<span>$fontcolor</span> = imagecolorallocate(<span>$image</span>, <span>0</span>, <span>0</span>, <span>0</span>);
imagestring(<span>$image</span>, <span>5</span>, <span>0</span>, <span>0</span>, <span>$vCodeString</span>, <span>$fontcolor</span>);
imagepng(<span>$image</span>);
imagedestroy(<span>$image</span>);

<span>?></span></span></span></code>

??代码很简单,这里就不做解释了。
下面把在firefox上(没有开启firebug)首次访问和刷新后的结果贴上:

首次访问:firefox php 验证码图片 多次请求问题 待解决
在验证码图片上右键另存为,保存到本地是:firefox php 验证码图片 多次请求问题 待解决
然后SESSION 里面存的也是2

刷新后:firefox php 验证码图片 多次请求问题 待解决

??下面把在firefox上(开启firebug)首次访问和刷新后的结果是(不贴图片了,太麻烦):
首次访问:1
在图片上右键另存为:3
firebug里面响应的为:3
SESSION里面是:3

总结:在没有开启firebug插件的时候,firefox页面请求一次(是两次中的第一次),服务器端的这个PHP文件实际是被请求了两次。在开启firebug插件的时候,firefox页面请求第一次,不知道哪里请求了第二次,firebug请求了第三次。

在chrome浏览器下均是访问了一次,页面显示的图片上的字符是SESSION中存储的字符,运行是正常的

最后的总结:网上查说是出现这种问题可能是firefox的一个bug,我想应该不是这么简单的问题把,记录在此,希望以后能够查清楚这是什么原因!!!

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了firefox php 验证码图片 多次请求问题 待解决,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn