Jump to content

header(Location: blah) not redirecting


trevzilla
Go to solution Solved by NotionCommotion,

Recommended Posts

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.