Home  >  Article  >  Backend Development  >  php网站后台建设(验证 验证码)有异常,求帮忙修改

php网站后台建设(验证 验证码)有异常,求帮忙修改

WBOY
WBOYOriginal
2016-06-13 11:57:471110browse

php网站后台建设(验证 验证码)有错误,求帮忙修改
我想判断输入的验证码是否与图片上的验证码是否一致,$_SESSION['code']是图片的验证码,number是(!
)我文本框输入的验证码,应该如何修改? 

程序如下,个人猜想问题出在if($_POST['number']==$_SESSION['code'])这一句上,请大神帮忙修改
header ( "Content-type: text/html; charset=gb2312" ); //设置文件编码格式
 class chkinput{
   var $name;
   var $pwd;

   function chkinput($x,$y)
    {
     $this->name=$x;
     $this->pwd=$y;
    }

   function checkinput()
   {
     include("../conn/conn.php");
     $sql=mysql_query("select * from tb_admin where name='".$this->name."'",$conn);
     $info=mysql_fetch_array($sql);
     if($info==false)
       {
          echo "<script>alert('不存在此管理员!');history.back();</script>";
          exit;
       }
      else
       {
          if($info[pwd]==$this->pwd)
   {
   if($_POST['number']==$_SESSION['code'])
      {
   header("location:index.php");}
   else 
      {
   echo "<script>alert('验证码输入错误!');history.back();</script>";
                   exit;}
            }
          else
           {
             echo "<script>alert('密码输入错误!');history.back();</script>";
             exit;
           }

      }    
   }
 }


    $obj=new chkinput(trim($_POST[name]),trim($_POST[pwd]));
    $obj->checkinput();

?>
------解决方案--------------------
应该在最顶加一句
session_start(); // 开启session,否则$_SESSION['code']会获取不到值。
------解决方案--------------------
$_POST['number']==$_SESSION['code']
输出变量是否有值不就知道?
------解决方案--------------------
没有开启session

var_dump($_SESSION['code']);//输出看看是否有值

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn