21,893
社区成员




<?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>";}
<?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']);
?>
<img src='验证' onClick="this.src='include/code.php#'+new Date().getTime()">