Welcome to WebmasterWorld Guest from 50.19.156.133

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

header redirect not working

     

andrewsmd

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

WebmasterWorld Senior Member 5+ Year Member



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

skoff

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

5+ Year Member



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]

Matthew1980

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

WebmasterWorld Senior Member 5+ Year Member



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:-

<?php
if($something = true){
header("location: this.site.com");
exit;
}
else{
header("location: that.site.com");
exit;
}
?>

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 ;)

Cheers,
MRb
 

Featured Threads

Hot Threads This Week

Hot Threads This Month