繁体   English   中英

该页面未在php中正确重定向

[英]the page isn't redirecting properly in php

当我以非管理员用户身份登录时,出现该错误

页面未正确重定向

这是login.php页面代码

<?php

require_once ('session.php');
if($_SESSION['userdetail'] !=FALSE){
    header('location: home.php');
            exit();
}
?>
<html>
<head><title>Login</title></head>
<body>
<form action="checklogin.php" method="post" enctype="multipart/form-data">
<table>
<tr><td>UserName:</td><td><input type="text" name="user_name"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" ></td></tr>

<tr><td colspan="2"><input type="submit" value="Submit"></td></tr>
</table>
</form> 

这是ckecklogin.php页面代码

<?php

if(!isset($_POST['user_name']) || !isset($_POST['password'])){
     header('location: login.php?log=error');
            exit();
}

if(empty($_POST['user_name']) || empty($_POST['password'])){
     header('location: login.php?log=error');
            exit();
}


require_once('includes/connection.php');
require_once('includes/book_functions.php');
require_once('includes/user_functions.php');
require_once ('session.php');

$user_name=$_POST['user_name'];
$user=  get_user_by_name($user_name);
db_close();
if(!$user){
    header('location: login.php?log=errusr');
            exit();
}
$password=$_POST['password'];
$user->passhash;
if (password_verify($password, $user->passhash)) {

    $_SESSION['userdetail']=$user;
    $_SESSION['userdetail']->passhash = NULL;
    header('location: home.php');
            exit();
}
else{
     header('location: login.php?log=errusr');
            exit();
}

它头我home.php和firefox让我这个错误,,这是如果我像普通用户一样登录,但如果我用我的管理员帐户登录,我的工作没有任何问题! 问题是什么?

发送标头之前,您不应有任何输出

坏:

    print_r($_SESSION['user_info']);
   header('location: home.php');

好:

   header('location: home.php');

坏:

echo $password=$_POST['password'];
echo $user->passhash;

好:

"emptyness"

使用ob_clean删除标头错误,最好使用window.location或通过javascript重定向

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM