我正在尝试在登录详细信息正确时重定向用户,但是我的标头功能没有运行,我已经测试了没有标题功能的if语句,通过回显的东西出来了,这很有用,所以我不知道为什么标题没有被执行。任何帮助,将不胜感激。
登录php
<?php
session_start();
require '../includes/class/login.php';
$login = new login();
$username_error=' ';
$password_error=' ';
$result=' ';
if(isset($_POST['username']) && $_POST['username'] !== ""){
$username = $_POST['username'];
$username = trim($username);
$user_exists = $login->user_exists($username);
if ($user_exists) {
$username_error = 'correct username entered ';
} else {
$username_error = 'username not found';
}
}
if(isset($_POST['password']) && $_POST['password'] !== ""){
$password = $_POST['password'];
$password = trim($password);
$password_check = $login->password_check($username,$password);
if ($password_check) {
$password_error = 'correct password entered ';
} else {
$password_error = 'password not found';
}
}
if (isset($_POST['login'])&& $_POST['login'] !== "") {
$log = $login->check_login($username,$password);
if ($log) {
$login->redirect('home.php');
//$user_session = 'welcome'.' '.$_SESSION['username'];
} else {
// Registration Failed
$password_error='Wrong username or password';
}
}
$return_data=array('username'=> $username_error, 'password'=> $password_error ,'user_session'=>$_SESSION['username']);
header('Content-Type: application/json');
echo json_encode($return_data);
exit();
?>
登录课程
public function redirect($url)
{
header("Location: $url");
}
答案 0 :(得分:1)
您有某种输出,导致“已发送标头”错误。您还禁用了php错误。启用错误并将其签出(或检查您的apache错误日志)。