问题
I'm developing a website and I purchased MAMP PRO. When I try to login through 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);
}
?>
the user should be redirected to home.php.
It used to work perfectly on the server I was using before but now I get just a white page (it stay basically on login_user.php) when I test it on my local machine. The connection to the database works fine. Does Header work properly on MAMP? I'm able to set the session and destroy it in logout.php but both files don't redirect after having set or destroyed the session. Any clue?
UPDATE: I get this error:
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
FIXED IT!!!
the problem was that in databaseconn.php I left blank the first line before <?php
I can't believe it. ;-)
回答1:
the problem was that in databaseconn.php I left blank the first line before <?php
you may want to refer to this link: "php-header-redirect-not-working"
来源:https://stackoverflow.com/questions/10788290/error-cannot-modify-header-information-headers-already-sent-by