验证码输入正确则跳转至百度!
code.php
<?php
session_start();
$_SESSION['cc']=getcode();
function getcode(){
$image=imagecreatetruecolor(100, 20);
header('Content-type:image/png');
imagefilledrectangle($image, 0, 0, 100, 20, getLightColor($image));
$str='1234567890abcdefghijklmnopqrstuvwxyz';
$string=substr(str_shuffle($str), 0,4);
for($i=0;$i<4;$i++){
imagechar($image, 5, ($i+0.2)*mt_rand(23, 26), mt_rand(0,5), $string[$i], getFontColor($image));
}
imageellipse($image, mt_rand(0, 100), mt_rand(0, 20), 200, 40, getFontColor($image));
$cell=mt_rand(5, 10);
for($i=0;$i<$cell;$i++){
imagesetpixel($image, mt_rand(0, 100), mt_rand(0, 20), getFontColor($image));
}
imagepng($image);
imagedestroy($image);
return $string;
}
function getLightColor($image){
return imagecolorallocate($image, mt_rand(130, 255), mt_rand(130, 255), mt_rand(130, 255));
}
function getFontColor($image){
return imagecolorallocate($image, mt_rand(0, 120),mt_rand(0, 120),mt_rand(0, 120));
}
?>
cheack.php
<html>
<head>
<title></title>
</head>
<body>
<form action="cheack.php" method="post">
<input type="text" name="code" id="code" value="" />
<input type="submit" value="提交"/>
</form>
<img src="code.php"/>
</body>
</html>
<?php
session_start();
if(!empty($_POST['code'])){
if($_POST['code']==$_SESSION['cc']){
echo '验证码正确';
header('Location: http://www.baidu.com/');
exit;
}else{
echo '<h5 style="color:darkred;">验证码错误</h5>';
}
}
?>