php 验证码中$_SESSION里得到的值为什么和图片不一致呢

yi890410 2010-07-27 05:01:31
php 验证码中$_SESSION里得到的值为什么和图片不一致呢


//验证码
yzm.php:
<?
session_start();
//生成验证码图片
//Header("Content-type: image/PNG");
$im = imagecreate(44,18);
$back = imagecolorallocate($im, 245,245,245);
imagefill($im,0,0,$back); //背景

srand((double)microtime()*1000000);
//生成4位数字
for($i=0;$i<4;$i++){
$font = imagecolorallocate($im, rand(100,255),rand(0,100),rand(100,255));
$authnum=rand(1,9);
@$vcodes .= $authnum;
imagestring($im, 5, 2+$i*10, 1, $authnum, $font);
}

for($i=0;$i<100;$i++) //加入干扰象素
{
$randcolor = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
imagepng($im,'yzm.png');
imagedestroy($im);

$_SESSION['VCODE'] = $vcodes;
?>



//提交页面
check.php:
<?php
include_once('include/yzm.php');
error_reporting(E_ALL);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>管理登录 - 多多留言本腾讯版</title>
<link href="css/css.css" rel="stylesheet" type="text/css">
</head>
<body>
<meta http-equiv="Page-Enter" content="blendTrans(Duration=1)" />
<meta http-equiv="Page-Exit" content="blendTrans(Duration=1)" />
<link rel="shortcut icon" href="favicon.ico"/>
<Script Language=Javascript Src="include/png.js"></Script>
<table width="750" border="0" align="center" cellpadding="6" cellspacing="0" background="images/head1.png">
<tr>
<td width="270" height="65" align="right"><a href="index.php"><img src="images/logo.png" alt="多多留言本腾讯版 - 留言本" border="0"></a></td>

<td height="80" align="center" valign="bottom">
<table width="75%" border="0" cellspacing="0" cellpadding="3">
<tr align="center">
<td><a href="index.php"><img src="images/1.png" width="36" height="36" border="0"><br>
浏览留言</a> </td>
<td><a href="add.php"><img src="images/4.png" width="36" height="36" border="0"><br>
签写留言</a></td>
<td><a href="admin_login.php"><img src="images/3.png" width="36" height="36" border="0"><br>

管理留言</a></td>
<td><a href="/"><img src="images/5.png" width="36" height="36" border="0"><br>
鸽联首页</a></td>
</tr>
</table></td>
</tr>
</table>
<form name="form1" method="post" action="login_check.php" onSubmit="return FrontPage_Form1_Validator(this)">
<table width="750" border="0" align="center" cellpadding="0" cellspacing="10">

<tr>
<td align="center">
<table width="97%" border="0" cellpadding="0" cellspacing="15">
<tr>
<td align="center" valign="top">
<table width="100%" border="0" cellpadding="5" cellspacing="0" class="border2">
<tr>
<td height="50" colspan="2"> <table width="95%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="9%" align="center"><font color="#0066FF"><img src="images/7.png"></font></td>

<td width="91%" class="font16"><img src="images/login.png"></td>
</tr>
</table></td>
</tr>
<tr>
<td width="35%" align="right"><font color="#333333">管理员帐号:</font></td>
<td width="65%"> <input name="admin_user" type="text" id="admin_user">
<font color="#999999">*</font></td>

</tr>
<tr>
<td align="right"><font color="#333333">管理员密码:</font></td>
<td><input name="admin_pass" type="password" id="admin_pass">
<font color="#999999">*</font></td>
</tr>
<tr>
<td align="right"><font color="#333333">输入验证码:</font></td>

<td>
<input name="unum" type="text" id="unum" size="10">
<font color="#999999">*</font> <IMG SRC='<?php echo 'yzm.png?'.time();?>' WIDTH='50' HEIGHT='25' BORDER=0 ALT=''></td>
</tr>
<tr>
<td align="right"> <script language=JavaScript>
function FrontPage_Form1_Validator(theForm)
{
if (theForm.admin_user.value == "")
{
alert("请输入管理员帐号!");
theForm.admin_user.focus();
return (false);
}
if (theForm.admin_pass.value == "")
{
alert("请输入管理员密码!");
theForm.admin_pass.focus();
return (false);
}
if (theForm.unum.value == "")
{
alert("请您输入验证码!");
theForm.unum.focus();
return (false);
}
return (true);
}
</script></td>
<td height="50" class="font14"> <input type="submit" name="Submit" value=" 登录 ">
<input name="action" type="hidden" id="action" value="add">
</td>

</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>

<div align="center">
<table width="98%" border="0" cellspacing="5" cellpadding="3">
<tr>
<td align="center"><p>Copyright © 2007 - 2008 <a href="http://www.crpa.info">Federal Pigeons</a> Inc. All Rights Reserved
<br>多多留言本腾讯版    版权所有    <a href="http://www.miibeian.gov.cn" target="_blank">京ICP备08080088号</a><br />
</p>

</td>
</tr>
</table>

</div>
</body>
</html>
<?php
include_once('include/config.inc.php');
include_once('include/yzm.php');
if (@$_POST['action'] == 'add')
{
$user = $_POST['admin_user'];
$pwd = $_POST['admin_pass'];
$unum = $_POST['unum'];
echo $unum;
echo $_SESSION['VCODE'];
if ($unum == $_SESSION['VCODE'])
{
$sql = "select * from tb_users where username=$user & password=$pwd";
$rs = mysql_query($sql);
$num = mysql_num_rows($rs);
if ($num > 0)
{
$_SESSION['ac'] = 'ok';
header("location:index.php");
}else
{
echo "<script language='javascript'>alert('用户名或密码错误');</script>";
}
}else
{
echo "<script language='javascript'>alert('验证码错误,请重新输入');</script>";
}
}

?>
...全文
1089 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
yi890410 2010-07-27
  • 打赏
  • 举报
回复
谢谢大家!问题解决了!
kyzy_yy_pm 2010-07-27
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 amani11 的回复:]
你include了不止一次啊,哎

编辑器里搜索一下吧
[/Quote]+果然
amani11 2010-07-27
  • 打赏
  • 举报
回复
你include了不止一次啊,哎

编辑器里搜索一下吧
kyzy_yy_pm 2010-07-27
  • 打赏
  • 举报
回复
<IMG SRC='<?php echo 'yzm.png?'.time();?>
首先生成图片,你调用的是生成的图片,并不是php文件,这样无法随时更新验证码,你在后面加个time()很可笑,根本没用,因为那是生成的图片(静的),劝你把img的src编程yzm.php?x=time()这个格式,而yzm.php中显示验证码
yi890410 2010-07-27
  • 打赏
  • 举报
回复
但是在其他页面还会用到验证码的
而且直接src='yzm.php'会不会影响安全问题呢?
yi890410 2010-07-27
  • 打赏
  • 举报
回复
回复 amani11:
还是不行

他不是同步得到的
Dleno 2010-07-27
  • 打赏
  • 举报
回复
imagepng($im,'yzm.png');//改成imagepng($im);
imagedestroy($im);
Dleno 2010-07-27
  • 打赏
  • 举报
回复
把include_once('include/yzm.php');删除了。
加上session_start();

<IMG SRC='<?php echo 'include/yzm.php?'.time();?>' WIDTH='50' HEIGHT='25' BORDER=0 ALT=''>
yi890410 2010-07-27
  • 打赏
  • 举报
回复
回复 kyzy_yy_pm:
src就是图片链接
不过这是链接的一个动态生成的图片

amani11 2010-07-27
  • 打赏
  • 举报
回复
哎,告诉你了,判断页面不要把yzm.php include进来

只要在前面session_start();就好了。。。。请问你这样子有问题么
kyzy_yy_pm 2010-07-27
  • 打赏
  • 举报
回复
是不是重写了啊,你<IMG SRC='<?php echo 'yzm.php?x='.time();?>
yi890410 2010-07-27
  • 打赏
  • 举报
回复
回复 xuzuning:

你说的是什么意思?
为什么多次执行?
每次不也是加载一次吗?
kyzy_yy_pm 2010-07-27
  • 打赏
  • 举报
回复
<IMG SRC='<?php echo 'yzm.png?'.time();?>
它的src是什么意思啊??
kyzy_yy_pm 2010-07-27
  • 打赏
  • 举报
回复
<IMG SRC='<?php echo 'yzm.png?'.time();?>'

img显示的总是第一次的是么?
xuzuning 2010-07-27
  • 打赏
  • 举报
回复
在你的代码中多次执行了 yzm.php ,而每次 yzm.php 的执行都会改变 $_SESSION 的值
通常在一个验证交互中 yzm.php 只能执行一次,除非你的脚本中设有“重新生成验证码”的功能
yi890410 2010-07-27
  • 打赏
  • 举报
回复
问题是$_SSSION可以得到值
就是和图片不一致
yi890410 2010-07-27
  • 打赏
  • 举报
回复
不是那个问题!include()已经包含进去了!
已经调试了好多次了!还是不行!
amani11 2010-07-27
  • 打赏
  • 举报
回复
你不应该在判断页面include_once('include/yzm.php');

只要在前面session_start();就行了
amani11 2010-07-27
  • 打赏
  • 举报
回复
判断数据页面,也要session_start();

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧