homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

header redirect not working

 8:33 pm on Mar 15, 2013 (gmt 0)

I'm guessing this a configurtion on my windows server but I'm getting the Warning: Cannot modify header information - headers already sent by error trying to redirect. I literally have this in the file
<?php header("Location: [google.com...] ?>
I double checked to make sure there was no lines or spaces before it. Does anyone know why this isn't working?
running a win 2k8 r2 server



 10:56 pm on Mar 15, 2013 (gmt 0)

This means that you may have something else before the header or another header redirect somewhere in your code. Do you include any other file that might have a header redirect too?

[edited by: skoff at 11:02 pm (utc) on Mar 15, 2013]


 10:59 pm on Mar 15, 2013 (gmt 0)

HI there Andrewsmd,

Aaah, this old chestnut! This error is generated only when information has already been sent to render on the webpage, if there is a redirect used, it should be the ONLY instruction after the <?php NO HTML, else this error is generated.

Read this article [php.net]

It's also good practice for you to have this sort of thing done too:-

if($something = true){
header("location: this.site.com");
header("location: that.site.com");

Having the exit there ensures that NOTHING else down stream gets actioned, therefore nothing erroneous gets sent to the screen - this ensures that the header is the only code parsed.

Hope as this helps you out.. Also, you're missing the ; in your example ;)


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved