为什么刷新验证码的时候SESSION 会把以前所有的验证码都记录下来?要怎样才能让session只存在一个验证码?
我的SESSION里面会把刷新的验证码全部保存,这样造成验证码永远出错,如何使验证码覆盖啊?
我的SESSION里面会把刷新的验证码全部保存,这样造成验证码永远出错,如何使验证码覆盖啊?
解决方案 »
- apache 怎么设置文件夹的读写权限?
- 如何用.sql文件还原数据库
- 关于数据库操作类的一个问题,$query = $db->query($sql)
- PHP中如何取得存贮过程中返回的记录集??ORACLE
- php 页面想shell脚本传参数
- ajax获取到的id数据,如何通过post方式提交该数据到post页面去。
- 这是咋回事?
- php.ini
- 如何防止刷新时数据重复提交
- 哪里有PHP计数器(基于文本文件,并且同一访客的多次访问只被计数一次)
- mysql查询中,用户输入内容是百分号%时,会查询出所有的数据,请问怎么解决?
- 求一正则 将<td class="t14l14">....... </td> 里的内容提取出来。
$auth_code = $_SESSION['auth_code'];然后验证 $auth_code 和提交的
不就不会了?你的验证码怎么设计的?
session_start();
header('Content-type:image/png');
//创建图片
$im = imagecreate(130,45)or die("Cannot Initialize new GD image stream");
$bg = imagecolorallocate($im,rand(50,200),rand(0,155),rand(0,155));
//第一次对imagecolorallocate()的调用会给基于调色板的图像填充背景色$fontColor = imageColorAllocate($im,255,255,255); //字体颜色
//$fontstyle = 'Roman.ttf';
$fontstyle = 'C:\WINDOWS\Fonts\arial.ttf';
//字体样式,这个可以从C:\windows\Fonts\文件夹下找到,我把它放到和Authcode,php文件同一个目录,这里可以替换其他的字体样式//产生随机字符
for($i=0;$i< 4;$i++)
{
$randAsciiNumArray = array(rand(48,57),rand(65,90));
$randAsciiNum = $randAsciiNumArray[rand(0,1)];
$randStr = chr($randAsciiNum);
imagettftext($im,30,rand(0,20)-rand(0,25),5+$i*30,rand(30,35),$fontColor,$fontstyle,$randStr);
$authcode .= $randStr;
}//用户和用户输入验证码做比较
$_SESSION['authcode'] = $authcode;//干扰线
for($i=0;$i<8;$i++)
{
$lineColor = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imageline($im,rand(0,130),0,rand(0,130),145,$lineColor);
} //干扰点
for($i=0;$i<250;$i++)
{
imagesetpixel($im,rand(0,130),rand(0,145),$fontColor);
}imagepng($im);
imagedestroy($im);
?>就这个代码,帮忙看看啊。谢了
session_start();
header("content-type:text/html;charset=utf-8");
if($yzm==$_SESSION['authcode'])
{
echo "1";
exit;
}else{
echo "0";
exit;
}
?>这是验证文件。我在这个文件里echo session里的验证码的时候发现新刷新的验证码全跟在后面。。
$authcode = '';
试一试。