PHP登陆验证码通不过,怎么回事啊? 本帖最后由 yjs901 于 2009-07-13 14:18:24 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 验证码页面 代码<?php session_start(); unset($str); //删除每次刷新前的字符串; Header("Content-type: image/png"); $a=range(0,9); $b=range(a,z); $c=range(A,Z); $d=array_merge($a,$b,$c); for( $i=0; $i<4; $i++ ) { $x= rand(0,61); $str .= $d[$x]; } $str=strtolower($str); //print_r($str);exit; $_SESSION['authnum']=$str; $img = imagecreate(70,30); $bgcolor= imagecolorallocate($img,136,193,255); //背景色; $foot= imagecolorallocate($img,255,90,145); //字体色; $rand= imagecolorallocate($img,255,150,50); //干扰色; imagestring($img,5,10,5,$str,$foot); //把字符串写在图上; for( $i=0; $i<=60; $i++) { imagesetpixel($img, rand(0,70), rand(0,30), $rand); //循环干扰点的元素; } imageline( $img, rand(0,70), rand(0,30), rand(0,70), rand(0,30), $rand);//在图象上画直线; imagepng( $img ); //输出图象; imagedestroy( $img ); //销毁图象 ?> 这个判断if(strtolower($CheckCode)!=$_SESSION['authnum'])总是true? echo strtolower($CheckCode)出来的值是什么啊? 我知道这个函数是这个意思,我的意思是说把它和session echo出来 echo strtolower($CheckCode)出来的值 是输入的值echo $_SESSION['authnum']出来的值 却为空。 echo $_SESSION['authnum']出来的值 却为空。说明你创建验证码的时候没把验证码写入session啊在你创建验证码那个程序里加上这几句session_start();$_SESSION['authnum'] = (产生的验证码的值);这样session就不会为空了 你看嘛,是写了的。<?php session_start(); unset($str); //删除每次刷新前的字符串; Header("Content-type: image/png"); $a=range(0,9); $b=range(a,z); $c=range(A,Z); $d=array_merge($a,$b,$c); for( $i=0; $i<4; $i++ ) { $x= rand(0,61); $str .= $d[$x]; } $str=strtolower($str); //print_r($str);exit; $_SESSION['authnum']=$str; $img = imagecreate(70,30); $bgcolor= imagecolorallocate($img,136,193,255); //背景色; $foot= imagecolorallocate($img,255,90,145); //字体色; $rand= imagecolorallocate($img,255,150,50); //干扰色; imagestring($img,5,10,5,$str,$foot); //把字符串写在图上; for( $i=0; $i<=60; $i++) { imagesetpixel($img, rand(0,70), rand(0,30), $rand); //循环干扰点的元素; } imageline( $img, rand(0,70), rand(0,30), rand(0,70), rand(0,30), $rand);//在图象上画直线; imagepng( $img ); //输出图象; imagedestroy( $img ); //销毁图象 ?> //print_r($str);exit; 不知道你这边打印出来了没 要是这边可以打出来的话 就是你验证strtolower($CheckCode)!=$_SESSION['authnum'] 这个的时候 SESSION没开启吧 print_r($str) 可以打出来, 验证页面最上面第一行代码就开启SESSION了啊 session_start(); session配置是不是有问题?session里是空的话,在生成验证码的时候 没有保存上。 你看看你的session是不是好的,做两个测试网页,第一个里设置session,然后再第二个网页里显示这个session。 调试方式:先直接对$_SESSION["authnum"]赋值,看看在提交验证时能否打印出来的$_SESSION["authnum"]结果 最好先注册这具SESSION变量。session_register("authnum")$_SESSION["authnum"]=值 我这样调试的,abc.php代码是:<?php session_start(); $_SESSION['authnum']='123456';?>bcd.php代码是:<?php session_start(); echo $_SESSION['authnum'];?>结果还是为空,看了下,SESSION文件是产生了的。 你这个问题是这样的 你输入的验证码的值 与session中的值比较时其实是 与 上一次 生成图片中的值比较 这就是 不同步问题 我也遇到了 不知道该怎么样解决 可以加我 msn chen1706#gmail.com (@) 一起讨论讨论 关于开发SNS 简单的留言版 一个困绕我多天的函数?希望在CSDN上得到解决! 请问为啥$row=mysql_fetch_array($result);这句老报错啊 有哪位高手做过paypal支付的,能否告诉我其中的运作原理 ob_start( array( &$this, 'cache_callback' ) );这是什么意思? sybase的text字段被截取 求助:登陆有效性的验证的问题(关于session) 如何得到本机的ip 有关mail函数的问题 swfupload的问题~请高手指点 pear 中的类能不能独立使用
<?php
session_start();
unset($str); //删除每次刷新前的字符串;
Header("Content-type: image/png");
$a=range(0,9);
$b=range(a,z);
$c=range(A,Z);
$d=array_merge($a,$b,$c);
for( $i=0; $i<4; $i++ )
{
$x= rand(0,61);
$str .= $d[$x];
}
$str=strtolower($str);
//print_r($str);exit;
$_SESSION['authnum']=$str;
$img = imagecreate(70,30);
$bgcolor= imagecolorallocate($img,136,193,255); //背景色;
$foot= imagecolorallocate($img,255,90,145); //字体色;
$rand= imagecolorallocate($img,255,150,50); //干扰色;
imagestring($img,5,10,5,$str,$foot); //把字符串写在图上;
for( $i=0; $i<=60; $i++)
{
imagesetpixel($img, rand(0,70), rand(0,30), $rand); //循环干扰点的元素;
}
imageline( $img, rand(0,70), rand(0,30), rand(0,70), rand(0,30), $rand);//在图象上画直线;
imagepng( $img ); //输出图象;
imagedestroy( $img ); //销毁图象
?>
总是true?
echo strtolower($CheckCode)出来的值 是输入的值
echo $_SESSION['authnum']出来的值 却为空。
在你创建验证码那个程序里加上这几句session_start();
$_SESSION['authnum'] = (产生的验证码的值);这样session就不会为空了
<?php
session_start();
unset($str); //删除每次刷新前的字符串;
Header("Content-type: image/png");
$a=range(0,9);
$b=range(a,z);
$c=range(A,Z);
$d=array_merge($a,$b,$c);
for( $i=0; $i<4; $i++ )
{
$x= rand(0,61);
$str .= $d[$x];
}
$str=strtolower($str);
//print_r($str);exit;
$_SESSION['authnum']=$str;
$img = imagecreate(70,30);
$bgcolor= imagecolorallocate($img,136,193,255); //背景色;
$foot= imagecolorallocate($img,255,90,145); //字体色;
$rand= imagecolorallocate($img,255,150,50); //干扰色;
imagestring($img,5,10,5,$str,$foot); //把字符串写在图上;
for( $i=0; $i<=60; $i++)
{
imagesetpixel($img, rand(0,70), rand(0,30), $rand); //循环干扰点的元素;
}
imageline( $img, rand(0,70), rand(0,30), rand(0,70), rand(0,30), $rand);//在图象上画直线;
imagepng( $img ); //输出图象;
imagedestroy( $img ); //销毁图象
?>
不知道你这边打印出来了没 要是这边可以打出来的话
就是你验证strtolower($CheckCode)!=$_SESSION['authnum'] 这个的时候 SESSION没开启吧
print_r($str) 可以打出来, 验证页面最上面第一行代码就开启SESSION了啊 session_start();
session里是空的话,在生成验证码的时候 没有保存上。
你看看你的session是不是好的,
做两个测试网页,第一个里设置session,然后再第二个网页里显示这个session。
session_register("authnum")
$_SESSION["authnum"]=值
<?php
session_start();
$_SESSION['authnum']='123456';?>bcd.php代码是:
<?php
session_start();
echo $_SESSION['authnum'];?>结果还是为空,看了下,SESSION文件是产生了的。