我正在开发一个网站,我购买了 MAMP PRO。当我尝试通过 login_user.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[] = 'username/password combination is incorrect!';
}else {
//set user session
$_SESSION['user_id'] = $login;
//redirect user to home
header('Location: home.php');
exit();
}
}
print_r($errors);
}
?>
用户应该被重定向到 home.php。
它曾经在我之前使用的服务器上完美运行,但现在当我在本地机器上测试它时,我只得到一个白页(它基本上停留在 login_user.php 上)。与数据库的连接工作正常。标头在 MAMP 上是否正常工作?我可以在 logout.php 中设置会话并将其销毁,但是在设置或销毁会话后,这两个文件都不会重定向。有什么线索吗?
更新:我收到此错误:
Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/mywebsite/core/database/databaseconn.php:2) in /Applications/MAMP/htdocs/mywebsite/login_user.php on line 26
修复!!!问题是,在 databaseconn.php 中,<?php
我无法相信它的第一行。;-)