Jump to content

header(Location: blah) not redirecting


trevzilla

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
https://forums.phpfreaks.com/topic/292438-headerlocation-blah-not-redirecting/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.