0

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. ;-)

Mat
  • 6,236
  • 9
  • 42
  • 55
  • empty(...) returns a boolean, so `=== true` is not needed – Cole Tobin May 28 '12 at 17:18
  • 1
    Blank white page indicates a parse error that killed the script, and error display is off. Check the server's and PHP's error logs to see if anything shows up, and/or turn on error display. There may also be some output occuring before the header() call, which will trigger "headers already sent" warnings, which may also be suppressed. – Marc B May 28 '12 at 17:26
  • thanks....this is the 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 – Mat May 28 '12 at 17:30
  • the problem was that in databaseconn.php I left blank the first line before – Mat May 28 '12 at 17:38

1 Answers1

0

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"

Community
  • 1
  • 1
Mat
  • 6,236
  • 9
  • 42
  • 55