Heim  >  Artikel  >  Backend-Entwicklung  >  header("Location: empManage.php")页面跳转到空白页,求解,该怎么处理

header("Location: empManage.php")页面跳转到空白页,求解,该怎么处理

WBOY
WBOYOriginal
2016-06-13 10:12:281057Durchsuche

header("Location: empManage.php")页面跳转到空白页,求解
loginProcess.php :


//接受用户的数据
//1.id
$id=$_POST["id"];
//2.密码
$password=$_POST["password"];

//到数据库去验证 mysql扩展库 mysqli扩展库
//1.得到连接
$conn=mysql_connect("localhost","root","root");

if(!$conn){
die("链接失败".mysql_errno());
}
//设置访问数据库的编码
mysql_query("set names utf-8",$conn) or die(mysql_errno());
//选择数据库
mysql_select_db("empmanage",$conn) or die(mysql_errno());

//发送sql语句,验证
//防止sql注入攻击,变化验证逻辑
$sql="select password from admin where id=$id";

//通过输入的id来获取数据库的密码,然后在和输入的密码比对.
$res=mysql_query($sql,$conn);

if($row = mysql_fetch_assoc($res)){
//查询到
//取出数据库密码
if(($row["password"]== md5($password))){
//说明合法
header("Location: empManage.php");

}

}
header("Location: login.php?errno=1");
exit();



mysql_free_result($res);
mysql_close($conn);


/*
//简单验证(不到数据库)
if($id=="100"&&$password=="123"){
//合法,跳转到empManage.php
header("Location:empManage.php");
//如果要跳转,则最好exit()
exit();
}else{
//非法用户
header("Location:login.php?errno=1");
exit();
}
*/
?>


代码如上,不连接数据库的话可以正常跳转到empManage.php  
连接数据库后出现空白页,跳转到的页面是loginProcess.php本身,怎么回事啊,在线等解答!!

------解决方案--------------------
header()前不能有输出;
必须置于页面HEAD的前面;
根据楼主的问题,检查:
数据库能否正常连接;
编码是否一致;
$row["password"] 和 md5($password) 是否有相等的值
------解决方案--------------------
我没看出代码有什么错误,建议你先调试看看。把header()改成echo(); 看看有没有输出什么。另外,看一下你是否有打开错误提示
------解决方案--------------------
$res=mysql_query($sql,$conn);
这句没有判错
可能导致 if($row = mysql_fetch_assoc($res)){ 有错,由于错误显示未打开,所以是空白页

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

探讨

$res=mysql_query($sql,$conn);
这句没有判错
可能导致 if($row = mysql_fetch_assoc($res)){ 有错,由于错误显示未打开,所以是空白页
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn