实现的功能是:在别人的网站登录进我的系统。在绘制验证码的php页开起session,然后给别人嵌入登录界面的代码包含绘制验证码页,最后提交到我的系统处理。
遇到的问题是:在火狐里面正常,但ie6,傲游里面输入验证码后提示错误,第二次输入正常进去系统。每次新打开浏览器输入验证码都会报错,第二次正常,现在不知道什么原因。
相关代码:
绘制验证码页:
<?php
header("Content-type: image/PNG");
session_start();//将随机数存入session中
$_SESSION['indexLoginRand']="";
$im = imagecreate(35,15); //制定图片大小$black = ImageColorAllocate($im, 0,0,0); //设定颜色
$white = ImageColorAllocate($im, 255,255,255);imagefill($im,0,0,$white); //区域填充$authnum = rand(1000,9999);
//将四位整数验证码绘入图片
$_SESSION['indexLoginRand']=$authnum;
imagestring($im, 5, 0, -1, $authnum, $black);for($i=0;$i<100;$i++) //加入干扰象素
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}ImagePNG($im);
ImageDestroy($im);
?>
嵌入登录页面:
<form action="http://" method="post">
<div align="center"><font class="black9">分机号 </font>
<INPUT name="ci_fax" type="text" class="input">
<br>
<font class="black9">密 码 </font>
<INPUT name="ci_loginpwd" type="password" class="input">
<br>
<font class="black9">验证码 </font>
<INPUT name="ci_rand" type="text" class="input_rand">
<img src="绘制验证码页"><br>
<INPUT name="user_login" type="submit" value="登 陆" class="inputbt">
<!--此处的“value”填写返回页面完整地址,用户登录时,填写的分机号码、密码、验证码有错误时,将返回这个页面-->
<input type="hidden" name="url" value="">
<INPUT type="button" value="注 册" onClick="location.replace('http://ip/reg.php?agent=1321');" class="inputbt">
<br>
<a href="http:///getpassword.php">忘记密码</a> <a href="http:///realcheck.php" >真实验证</a>
</div>
</form> 帮我解决问题的送上100分,在线等!!
遇到的问题是:在火狐里面正常,但ie6,傲游里面输入验证码后提示错误,第二次输入正常进去系统。每次新打开浏览器输入验证码都会报错,第二次正常,现在不知道什么原因。
相关代码:
绘制验证码页:
<?php
header("Content-type: image/PNG");
session_start();//将随机数存入session中
$_SESSION['indexLoginRand']="";
$im = imagecreate(35,15); //制定图片大小$black = ImageColorAllocate($im, 0,0,0); //设定颜色
$white = ImageColorAllocate($im, 255,255,255);imagefill($im,0,0,$white); //区域填充$authnum = rand(1000,9999);
//将四位整数验证码绘入图片
$_SESSION['indexLoginRand']=$authnum;
imagestring($im, 5, 0, -1, $authnum, $black);for($i=0;$i<100;$i++) //加入干扰象素
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}ImagePNG($im);
ImageDestroy($im);
?>
嵌入登录页面:
<form action="http://" method="post">
<div align="center"><font class="black9">分机号 </font>
<INPUT name="ci_fax" type="text" class="input">
<br>
<font class="black9">密 码 </font>
<INPUT name="ci_loginpwd" type="password" class="input">
<br>
<font class="black9">验证码 </font>
<INPUT name="ci_rand" type="text" class="input_rand">
<img src="绘制验证码页"><br>
<INPUT name="user_login" type="submit" value="登 陆" class="inputbt">
<!--此处的“value”填写返回页面完整地址,用户登录时,填写的分机号码、密码、验证码有错误时,将返回这个页面-->
<input type="hidden" name="url" value="">
<INPUT type="button" value="注 册" onClick="location.replace('http://ip/reg.php?agent=1321');" class="inputbt">
<br>
<a href="http:///getpassword.php">忘记密码</a> <a href="http:///realcheck.php" >真实验证</a>
</div>
</form> 帮我解决问题的送上100分,在线等!!
接收post的页面
print_r($_SESSION);
print_r($_POST['ci_rand']);
比较一下
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-type: image/PNG");
?>
可能是cache原因.
加上这个试试!
看一下有没有用~http://www.php002.cn/phpclass/phptupianyanzhengmaleiAbsCaptchalei_10569.html
<img src='验证' onClick="this.src='include/code.php#'+new Date().getTime()">打印出处理页面的
print_r( $_SESSION['indexLoginRand'] ); 看一下是什么情况
点完图片结果是一个大红叉
session值是能够正确得到的.
可能是你代码哪块有问题.
不知道你是如何验证的.
//code.php<?php
session_start();//将随机数存入session中
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-type: image/PNG"); $_SESSION['indexLoginRand']="";
$im = imagecreate(35,15); //制定图片大小 $black = ImageColorAllocate($im, 0,0,0); //设定颜色
$white = ImageColorAllocate($im, 255,255,255); imagefill($im,0,0,$white); //区域填充 $authnum = rand(1000,9999);
//将四位整数验证码绘入图片
$_SESSION['indexLoginRand']=$authnum;
imagestring($im, 5, 0, -1, $authnum, $black); for($i=0;$i <100;$i++) //加入干扰象素
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
} ImagePNG($im);
ImageDestroy($im);
?>
//test2.html
<form action="index.php" method="post">
<div align="center"> <font class="black9">分机号 </font>
<INPUT name="ci_fax" type="text" class="input">
<br>
<font class="black9">密 码 </font>
<INPUT name="ci_loginpwd" type="password" class="input">
<br>
<font class="black9">验证码 </font>
<INPUT name="ci_rand" type="text" class="input_rand">
<img src="code.php"> <br>
<INPUT name="user_login" type="submit" value="登 陆" class="inputbt">
<!--此处的“value”填写返回页面完整地址,用户登录时,填写的分机号码、密码、验证码有错误时,将返回这个页面-->
<input type="hidden" name="url" value="">
<INPUT type="submit" value="注 册" class="inputbt">
<br>
<a href="http:///getpassword.php">忘记密码 </a> <a href="http://l/index.php" >真实验证 </a>
</div>
</form>
//index.php
<?php
session_start();
echo $_POST['ci_rand'] . "<br/>";
print_r($_SESSION['indexLoginRand']);
?>
唉
<?php
require_once ("../bin/db.php");
$ci_fax = trim($_POST['ci_fax']);
$ci_loginpwd = strtoupper(md5($_POST['ci_loginpwd']));
$ci_rand = trim($_POST['ci_rand']);
$return_url = $_POST['url'];
$ci_rand_system = $_SESSION['indexLoginRand'];
if (strcmp($ci_rand, $ci_rand_system) != 0) {
session_unregister('indexLoginRand');
echo "<script>alert(\"验证码输入错误,请重新输入!\");location.replace('$return_url');</script>";}部分后台源代码 各位大侠参考下,总弹出验证码错误,重新输入
,看ie6下有问题的那次验证码提交,究竟是这两个东西都是什么样的值。
isset($_SESSION['indexLoginRand'])看一下;echo $ci_rand;
echo $ci_rand_system;
对比一下不就清楚了!
1、php 页面里加入清除缓存的代码,上面有人回复了这个代码
2、这里修改一下<font class="black9">验证码 </font>
<INPUT name="ci_rand" type="text" class="input_rand">
<img src="绘制验证码页"> <br>
修改为:
<font class="black9">验证码 </font>
<INPUT name="ci_rand" type="text" class="input_rand">
<img src="绘制验证码页?r=<?php echo rand(0,100)?>"> <br>