我的登录时遇到一些问题:所有验证都有效,但在提交时,页面变为空白(使用url:login.php)而不是假设的index.php-类似于下面的屏幕截图 这是我的代码和截图:
<?php
logged_in_redirect(); //to prevent access from user already logged in
//when Line 2 is un-commented it displays the following error message:"Fatal error: Call to undefined function logged_in_redirect() in /www/htdocs/w00f3b5f/kari/SAMS/login.php on line 2”
include 'core/init.php';
if(empty($_POST) === false) {
$email_address = $_POST['email_address'];
$password = $_POST['password'];
if(empty($email_address) === true || empty($password) === true) {
$errors[] = 'You need to enter an email and password’;
} else if (email_exists($email_address) === false) { //edit to suit my system
$errors[] = 'This email address cannot be found. Have you registered?’;
} else if (user_active($email_address) === false) {
$errors[] = 'Your account has not been activated!’;
} else {
//validate email_address and password
$login = login($email_address, $password);
if ($login === false) {
$errors[] = 'The email address/password combination is incorrect’;
} else {
$_SESSION['user_id'] = $login; //login returns the user id
header('Location: index.php');
exit();
}
}
} else {
$errors[] = 'No data received';
}
include 'includes/overall/header.php';
if(empty($errors) === false) {
?>
<h2>We tried to log you in, but ...</h2>
<?php
echo output_errors($errors);
}
include 'includes/overall/footer.php';
?>
下面的屏幕截图是从重定向中删除exit()的结果,我知道不应该这样做。我真的不知道错误的来源在哪里。 P.S:问候应该是“你好,[名字]!但它不显示登录用户的名字。
答案 0 :(得分:0)
$errors[] = 'You need to enter an email and password’;
this ^
和
$errors[] = 'Your account has not been activated!’;
this ^
将是您的问题,请将其替换为'
。