header redirect not working.

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
vertige
Forum Newbie
Posts: 3
Joined: Thu May 16, 2002 3:18 pm

header redirect not working.

Post by vertige »

header("Location: http://www.example.com/"); exit;

does nothing for me. I have placed the code at the very top of my template right after the <?PHP

When i access the page all I get is a popup error message "Document contains no data. Try again later.. blah, blah, blah

I'm running netscape 4.7.
PHP 4.1, Webstar on OSX.

Thanks
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

is there a point in putting exit?
vertige
Forum Newbie
Posts: 3
Joined: Thu May 16, 2002 3:18 pm

header("Location:) not working

Post by vertige »

exit or no exit it won't work
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Code: Select all

<?
header("Location: http://www.example.com");
?>
hmm, if that doesn't work, I have no clue.... I don't know anything about use on different OS's...maybe one of the guru's will reply :-/
User avatar
fatal
Forum Contributor
Posts: 118
Joined: Sat Apr 20, 2002 10:47 am
Location: East Coast

Post by fatal »

To send out headers, the have to be the first thing sent on the page. I learned that from trying to make a page that was restricted access, eventually i found out that headers have to be the first thing sent. Or else you get errors for the header line of code.

http://www.php.net/manual/en/function.header.php
From the manuel:

Note: The HTTP status header line will always be the first sent to the client, regardless of the actual header() call beeing the first or not. The status may be overridden by calling header() with a new status line at any time unless the HTTP headers have already been sent.

Post Reply