Forum Moderators: coopster

Message Too Old, No Replies

Can't have mutliple header() that direct to the same page in 1 script

         

tyrone04

6:50 am on Mar 23, 2006 (gmt 0)

10+ Year Member



I found this to be very weird so maybe someone could shed some light on why it's not working.

So basically I have some codes like this:

//checks database to see if the person already exists
$query = "......"
$result = "......."
$row = ".........."
if($row) {
//set some cookies

//then redirect to another script
header("Location: http://www.example.com/member.php");
} else {

//don't set any cookies

//just redirect to that same page like above
header("Location: http://www.example.com/member.php");
}

Notice how the two header() lines redirect to the same location, and that's where it doesn't work...
Somehow the header() doesn't redirect to the page in the "else" part....I have to change the URL to something else in order for it to work. In other words, if I tell it to redirect to a different page like member_new.php or anything, then it works. It just doesn't work if it's the same URL as above.

elgumbo

10:54 am on Mar 23, 2006 (gmt 0)

10+ Year Member



I've no idea why it isn't redirecting but what happens if you take the redirect out of the loop? eg:

//checks database to see if the person already exists
$query = "......"
$result = "......."
$row = ".........."
if($row)
{
//set some cookies
}

//then redirect to another script
header("Location: http://www.example.com/member.php");

edit
----

if you still have a problem it could be something on the member.php page that is incorrect. Are you maybe checking for the cookies when they are not there?

tyrone04

6:57 pm on Mar 23, 2006 (gmt 0)

10+ Year Member



elgumbo, you were so right! I did have some codes on top of my member.php script that checked for the existence of a cookie, if not bump the user back to the login page. I can't believe I didn't remember that...and I spent many hours figuring out why the redirect didn't work. Oh well,,,,that's what happens when you're a newbie....

Thanks for you help!

elgumbo

8:23 am on Mar 27, 2006 (gmt 0)

10+ Year Member



No problem. Been there, done that ;)