Home  >  Article  >  Backend Development  >  PHP登录跳转,该怎么处理

PHP登录跳转,该怎么处理

WBOY
WBOYOriginal
2016-06-13 10:15:24715browse

PHP登录跳转
session_start();
include("config.php");//连接数据库
$username=$_POST['user'];
$word=$_POST['password'];
$userword=md5(trim($word));//MD5转换密码
$id=$_POST['user_id'];
if($id=="student")
{
$result_psword=mysql_query("select S_PS from STUDENT where S_ID='$username'");
/*while ($rows=mysql_fetch_array($result_psword)){}*/
if(!$result_psword)
{
echo "用户不存在,请先注册";
echo "<script>setTimeout(function(){window.location.href='../regist.php'}, 2000);</script>";
exit;
}
else if($result_psword==$userword)
{

$_SESSION['login']='学生';
echo "<script>window.location.href='../student/student.php';</script>";
}
}
登录后发现没有跳转,直接停在login.php页面里。
$username,$userword,$id都测试了有传进去值,我想就是
$result_psword=mysql_query("select S_PS from STUDENT where S_ID='$username'");
这句的问题了。
$reslt_psword我想测试里面的值都测试不出来,这个里面到底包含着什么东西?
($result_psword==$userword)这句话直接判断为什么会不行?
做毕设中,分不敢给多啊··留点以后用。

------解决方案--------------------

PHP code
<?phpsession_start ();include("config.php");//连接数据库$username=$_POST['user'];$word=$_POST['password'];$userword=md5(trim($word));//MD5转换密码$id=$_POST['user_id'];if($id=="student"){$result_psword = mysql_query("select S_PS from STUDENT where S_ID='$username'");if(! $result_psword)    echo "mysql error message:". mysql_error();$row = mysql_fetch_assoc($result_psword);   if($rows) {      echo "用户不存在,请先注册";      echo "<script>setTimeout(function(){window.location.href='../regist.php'}, 2000);";      exit;   }   else if($row['S_PS'] == $userword ) {      $_SESSION['login']='学生';      header("Location: ../student/student.php");   }else      echo "用户密码错误";}else   echo "id {$id} 不是 student";<br><font color="#e78608">------解决方案--------------------</font><br>mysql_query()返回的是资源集。因此不能那么判断。<br>if(!$result_psword)<br>{<br>echo "用户不存在,请先注册";<br>echo "<script>setTimeout(function(){window.location.href='../regist.php'}, 2000);</script>";<br>exit;<br>}<br>==》改为:<br>if(!mysql_num_rows($result_psword))<br>{<br>echo "用户不存在,请先注册";<br>echo "<script>setTimeout(function(){window.location.href='../regist.php'}, 2000);</script>";<br>exit;<br>}<br><font color="#e78608">------解决方案--------------------</font><br>http://dev.mysql.com/doc/refman/5.1/zh/index.html<br><font color="#e78608">------解决方案--------------------</font><br>判断逻辑写反了<br>你的<br>if(!$_SESSION['login']||$_SESSION['login']!='管理员'||$_SESSION['login']!='教师'||$_SESSION['login']!='学生')<br>表示只要有有一个成立就进入<br>但是,比如当 $_SESSION['login'] = '管理员' 时,<br>$_SESSION['login']!='教师' 和 $_SESSION['login']!='学生'<br>都会成立的<br>应写作<br><br>if(!$_SESSION['login'] || ($_SESSION['login']!='管理员' && $_SESSION['login']!='教师' && $_SESSION['login']!='学生'))<br><div class="clear">
                 
              
              
        
            </div>
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