form.php<?php
if (isset($_REQUEST['authcode'])){
session_start();
if ($_REQUEST['authcode'] == $_SESSION['authcode']){
echo "输入正确";
}else{
echo "输入错误";
}
exit();
}
?>
html>
验证码图片:
">
请输入验证码:
captcha.php<?php
session_start();
$image = imagecreatetruecolor(100,30);
$bgColor = imagecolorallocate($image,255,255,255);
imagefill($image,0,0,$bgColor);
/* for($i=0;$i<4;$i++){
$font = 6;
$col = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
$s = rand(0,9);
$x = ($i*100/4)+rand(5,10);
$y = rand(5,10);
imagestring($image,$font,$x,$y,$s,$col);
}*/
/*字母+数字*/
$captch_code = '';
for($i=0;$i<4;$i++){
$font = 6;
$col = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
$data = "abcdefghgkmnpqrstuvwxyABCDEFGHJKLMNPQRSTUVWXYZ123456789";
$s = substr($data,rand(0,strlen($data)-1),1);
$captch_code.=$s;
$x = ($i*100/4)+rand(5,10);
$y = rand(5,10);
imagestring($image,$font,$x,$y,$s,$col);
}
$_SESSION['authcode'] = $captch_code;
/*增加点干扰元素*/
for($i=0;$i<200;$i++){
$pointColor = imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));
imagesetpixel($image,rand(1,99),rand(1,29),$pointColor);
}
/*增加线的干扰*/
for($i=0;$i<3;$i++){
$lineColor = imagecolorallocate($image,rand(80,220),rand(80,220),rand(80,220));
imageline($image,rand(1,99),rand(1,29),rand(1,99),rand(1,29),$lineColor);
}
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
有学过的同学 给指点指点,最容易忽视的问题在哪?