我的代码有问题吗?它可以工作,但它没有重定向到我的index.php它总是在表单所在的login.php中结束。
<?php
include 'core/ini.php';
if (empty($_POST) === false) {
$username = $_POST ['username'];
$password = $_POST ['password'];
if (empty ($username) === true || empty ($password) === true ) {
$errors[] = 'You need to enter a username and password!';
} else if (user_exists($username) === false) {
$errors[] = 'We can\'t find that username. Have you registered?';
} else if (user_active($username) === false) {
$errors[] = 'You haven\'t activated your account! ';
} else {
$login = login($username, $password) ;
if ($login === false) {
$errors[] = 'That username/password combination is incorrect ';
} else {
$_SESSION['user_id'] = $login;
header('Location :index.php');
exit();
}
}
print_r($errors);
}
?>
thanks!
EDIT *
this is my login.php
<?php
include 'core/ini.php';
if (empty($_POST) === false) {
$username = $_POST ['username'];
$password = $_POST ['password'];
if (empty ($username) === true || empty ($password) === true ) {
$errors[] = 'You need to enter a username and password!';
} else if (user_exists($username) === false) {
$errors[] = 'We can\'t find that username. Have you registered?';
} else if (user_active($username) === false) {
$errors[] = 'You haven\'t activated your account! ';
} else {
$login = login($username, $password) ;
if ($login === false) {
$errors[] = 'That username/password combination is incorrect ';
} else {
$_SESSION['user_id'] = $login;
header('Location :index.php');
exit();
}
}
print_r($errors);
}
?>
这是流程的所在。我不知道我应该在哪里开始我的开始课程,但我不知道为什么它没有错误。
答案 0 :(得分:0)
我猜你错过了页面顶部的session_start();
,因为你正在存储会话。发起session_start();
。
您的login()
函数也会返回TRUE吗?回显一些东西来检查函数是否按预期返回TRUE。
答案 1 :(得分:0)
您必须在页面顶部使用session_start
,我认为您应该在标题位置后删除exit
。
答案 2 :(得分:0)
将header('Location :index.php');
更改为header('Location: index.php');
该空间可能是原因。