PHP Newbie Question
Hey gang,
I'm just learning PHP, and I need to send the browser to another URL from my script. It seems like a really common/standard thing to do, but I can't seem to find a built-in command for doing this. I found the header() function, but I'm not sure it does what I need... does it? Does anyone have a simple answer?
Thanks!
HeyCoolAid!
Wednesday, November 19, 2003
header(Location: http://yoururl.com);
I think.
R
Wednesday, November 19, 2003
header("location:http://yourAbsoluteUrlHere");
obm
Wednesday, November 19, 2003
Correction:
header("Location: http://www.example.com/");
R
Wednesday, November 19, 2003
Don't forget the quotes:
header('Location: http://yoururl.com');
There is more information about this in the manual for the header function.
Almost Anonymous
Wednesday, November 19, 2003
When in doubt on php, goto http://www.php.net/
The search on the main page is *wonderful* (as is the documentation behind it.
The answer you want is at:
http://us4.php.net/manual/en/function.header.php
Quote:
The second special case is the "Location:" header. Not only does it send this header back to the browser, but it also returns a REDIRECT (302) status code to the browser unless some 3xx status code has already been set.
<?php
header("Location: http://www.example.com/"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
RocketJeff
Wednesday, November 19, 2003
Hum, well when I tried to use this function before (modified with the URL I wanted):
<?php
header("Location: http://www.example.com/"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
... I got the following error:
Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/sundayplus/ops1/index.php:8) in /www/htdocs/sundayplus/ops1/index.php on line 12
I'm probably just doing something really dumb... but I haven't figured out what it is yet. ;)
HeyCoolAid!
Wednesday, November 19, 2003
HeyCoolAid,
The header must the the very first thing that gets written to the client.
The problem here is that something has already been written.
Have any other headers or echos been made before this line?
Is there any white space in the PHP page before your first <?PHP ?
Ged Byrne
Wednesday, November 19, 2003
Ooooh... my php tag is inside some regular html stuff. Do you mean that if I remove all of that it should work?
HeyCoolAid!
Wednesday, November 19, 2003
D'oh! You were right Ged... that was it. See, I knew it was some dumb little thing. Thanks guys!
HeyCoolAid!
Wednesday, November 19, 2003
I think
http://forums.devshed.com
and
http://www.sitepointforums.com are the best FORUMS to ask PHP related questions.
JD
http://jdk.phpkid.org
JD
Wednesday, November 19, 2003
Recent Topics
Fog Creek Home
|