trevzilla Posted November 13, 2014 Share Posted November 13, 2014 So I have a site in which a user logs in. When they click the submit button on the login page, it checks to see if a username and password combo exists in an array. If it doesn't exist, the user is supposed to be redirected back to the login page. This code USED to work, and I think I added one thing completely away from the code that should do any of this, but now it doesn't work any more. I've read that you can't have anything output before the header code, so I've double checked, and can't find any spaces, echo statements or anything of the like. I've thrown in a random echo statement to see if my if's else's were being entered correctly, and they are. I definitely get into the else statement with the header(location: blah) code when an incorrect username/password is used... Here's the code I'm looking at. (And there is More HTML under this...) <?php session_start();?> <?php include("passwords.php"); //this statement will be entered if coming from the login.php page. if ($_POST["ac"]=="log"){ //check if submitted username and password exist in $PASSWORD array if ($PASSWORD[$_POST["username"]]==$_POST["password"]){ //set various session variables $_SESSION["username"]=$_POST["username"]; $_SESSION["firstname"]=$FIRSTNAME[$_POST["username"]]; $_SESSION["lastname"]=$LASTNAME[$_POST["username"]]; $_SESSION["email"]=$EMAIL[$_POST["username"]]; } else{ //if username and password do not exist, set session variable for "incorrect username/password" message and redirect to login.php $_SESSION['incorrect'] = "incorrect"; header('Location: login.php'); }; }; // check if user is logged in already when they are coming from a random place. If not, redirect to login.php check_logged(); ?> Any ideas out there why my header('Location: login.php'); line is not working? Quote Link to comment Share on other sites More sharing options...
Solution NotionCommotion Posted November 13, 2014 Solution Share Posted November 13, 2014 You sent content to the browser before calling the header (a big no-no). Happened right between when you call session_start() and include your password.php file. Quote Link to comment Share on other sites More sharing options...
trevzilla Posted November 13, 2014 Author Share Posted November 13, 2014 That was it! Thanks so much. Didn't realize that line was sending info to the browser. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted November 13, 2014 Share Posted November 13, 2014 It doesn't take much! Glad to be of help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.