simple PHP if statement question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
taco_pants
Forum Newbie
Posts: 2
Joined: Sat Sep 04, 2010 10:00 am

simple PHP if statement question

Post by taco_pants »

I've simplified the following code just to get an understanding why the code is executed this way. This code will redirect to pagetwo.php instead of executing the if statement and redirecting to pageone.php. Why is this? I know it's easy to have pagetwo.php in an else statement and all will be fine but I'm curious why it wouldn't work this way also.

Code: Select all

$check = 1;

if ($check == 1)
{
  header("Location: ../pageone.php");
}

header("Location: ../pagetwo.php");
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: simple PHP if statement question

Post by josh »

Have you taken a look at the headers that get output by that script? You can use the php socket functions to debug this kind of stuff. Most likely your script is outputting both Location: headers, the latter of which is being applied.
taco_pants
Forum Newbie
Posts: 2
Joined: Sat Sep 04, 2010 10:00 am

Re: simple PHP if statement question

Post by taco_pants »

hmm, so if you don't put an exit(); after the redirect inside the if statement the code will continue to execute and send both headers, with the last one, pagetwo.php, being the page that is loaded since it was last.
Post Reply