在注册码的php页写了这样一些代码 imagePng($image);
$_SESSION['seccode'] = $code;//创建SESSION
if ($_GET['verif']) {
if ($_GET['verif']!=$_SESSION['seccode']) {
echo "验证码不正确";
}
}
imagedestroy($image);//销毁图像,释放内存想通过ajax 在注册页面显示用户验证码输入是否正确可总是不能显示 是怎么回事谢谢
$_SESSION['seccode'] = $code;//创建SESSION
if ($_GET['verif']) {
if ($_GET['verif']!=$_SESSION['seccode']) {
echo "验证码不正确";
}
}
imagedestroy($image);//销毁图像,释放内存想通过ajax 在注册页面显示用户验证码输入是否正确可总是不能显示 是怎么回事谢谢
header("Content-type: image/png;charset=utf-8");
$_SESSION['seccode'] = "";
$width = 100;//图片长度
$height = 41;//图片高度
$len = 5;//验证码长度
$noise = true;//是否生成杂点
$noisenum = 100;//杂点数量
$bgcolor = "#ffffff";//背景色
$image = imagecreate($width,$height);//创建图像
$back = getcolor($bgcolor);
$font = 'arial.ttf';
$randColor = imagecolorallocate($image, mt_rand(100, 255), mt_rand(100, 255), mt_rand(0, 255));
imagefilledrectangle($image,0,0,$width,$height,$back);//为图像填充颜色
$code = random($len);//创建随机数 for ($i = 0; $i < 2; $i++) {
imagesetthickness ($image,mt_rand(1,10));
imageline ($image , mt_rand(7,85), mt_rand(7,35), mt_rand(25,95), mt_rand(15,40), $randColor );
}
for ($i = 0; $i < sizeof($code); $i++) {
$codecolor = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagettftext($image, mt_rand(15,20), mt_rand(-10,10), 9+17*$i, mt_rand(25,30), $codecolor,$font, $code[$i]);
}
$code=$code[0].$code[1].$code[2].$code[3].$code[4]; if($noise == true) setnoise();//创建杂点
imagePng($image);
$_SESSION['seccode'] = $code;//创建SESSION
if ($_GET['verif']) {
if ($_GET['verif']!=$_SESSION['seccode']) {
echo "验证码不正确";
}
}
imagedestroy($image);//销毁图像,释放内存
//字体颜色
function getcolor($color)
{
global $image;
$color = preg_replace ("/^#/","",$color);
$r = $color[0].$color[1];
$r = hexdec ($r);
$b = $color[2].$color[3];
$b = hexdec ($b);
$g = $color[4].$color[5];
$g = hexdec ($g);
$color = imagecolorallocate ($image, $r, $b, $g);
return $color;
}
function random($length) {
$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
for($i = 0; $i < $length; $i++) {
$hash[$i]= $str[mt_rand(0,61)];
}
return $hash;
}
function setnoise()
{
global $image, $width, $height, $back, $noisenum;
for ($i=0; $i<$noisenum; $i++){
$randColor = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($image, rand(0, $width), rand(0, $height), $randColor);
}
}
?>
<body>
...
<script type='text/javascript' src='jquery1.6.2.js'></script>
<script type='text/javascript'>
var ses=document.form[0].getElementsByName('verif').value
$(document).ready(function(){
$("input[@name=verif]").blur(function(){
$("div[@name=session]").load('verification.php',{session:ses});
});
});
</script>
</body>
</html>我的ajax 用的是jquery 大体意思就是
将用户的验证码送到 验证码页面 然后将返回的内容显示在页面上某个div中 可总是实现不了 验证码页面上的 用户输入的验证码和$_SESSION()的比较 对么
imagePng($image);
$_SESSION['seccode'] = $code;//创建SESSION
if ($_GET['verif']) {
if ($_GET['verif']!=$_SESSION['seccode']) {
echo "验证码不正确";
}
}
imagedestroy($image);//销毁图像,释放内存
这些代码放的位置 对不对