Header(“Location”) on PHP


So check out this code…..

if(1== 1)
header(“Location: index.php”);
header(“Location: http://www.google.com”);

This simple code will be expected to redirect to index.php since 1==1 is always true. And for a weird reason it returns to redirect to http://www.google.com.

Maybe for a reason i didn’t quite understand this, but it should be written like this

if(1== 1)
header(“Location: index.php”);
header(“Location: http://www.google.com”);

As mentioned before the only logical explanation is that this command is a client side command that means the script doesn’t stop from being executed till end. My guess is that header location, first of all has to be executed before anything has sent to html output, so it does fill the html with this line


6 Responses to “Header(“Location”) on PHP”

  1. 1 Me

    if(1== 1)
    header(”Location: index.php”);
    header(”Location: http://www.google.com”);

  2. Any ideas why the following line won’t work:

    header(‘Location: index.php? page=list-album’);

    but the following line does work as a test to see if Header works:

    header(‘location: index.html’)

  3. 3 worthposting

    header(’Location: index.php?page=list-album’);

    without a space just before page

  4. Sorry tried that already without the space,,,,,,,no joy either. the login page still reappears.

  5. 5 worthposting

    Maybe an invalid page Get variable somewhere redirects somewhere else.

  6. 6 worthposting

    Dont Forget that header(“Location: somewhere.html”); can only work when nothing else has been output to page.
    Place it above all.

    Error Suppression Can Hide the error message
    warning: Cannot modify header information – headers already sent by ….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: