php header(Location: )

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
crs992
-


Joined: 15 Jun 2005
Posts: 32

PostPosted: Fri Mar 17, 2006 12:29 am    Post subject: php header(Location: ) Reply with quote

is there anyway that I can make something like this:
Code:
<?
$url = $_GET['url'];
echo'<a href="/">return to home page</a>';
header("Location: $url");
exit;
?>

work?
i wnat it so when you go to mysite.com/redir?url=http://www.google.com it shouws google and a link back to my site but i keep getting this error:
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Abyss Web Server\htdocs\redir\index.php:1) in C:\Program Files\Abyss Web Server\htdocs\redir\index.php on line 3
please help.
thanks.
_________________
http://crs992.bounceme.net:8080/
Back to top View user's profile Send private message Visit poster's website
Yami King
-


Joined: 08 Sep 2005
Posts: 120

PostPosted: Fri Mar 17, 2006 12:33 am    Post subject: Reply with quote

the header function must be the first function called
Back to top View user's profile Send private message Send e-mail
olly86
-


Joined: 25 Apr 2003
Posts: 993
Location: Wiltshire, UK

PostPosted: Fri Mar 17, 2006 12:39 am    Post subject: Re: php header(Location: ) Reply with quote

Code:
<?
$url = $_GET['url'];
header("Location: $url");
?>


No as the error tells you, the header command must be the first instruction returned to the browser. The "header location" command redirects the users browser to the specified address in the arguments, and appears in the html head section.

More info on the header command is available here: http://uk.php.net/manual/en/function.header.php

To achieve the effect you are after you could use frames....
_________________
Olly
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Fri Mar 17, 2006 9:01 pm    Post subject: Re: php header(Location: ) Reply with quote

crs992,

headers must be changed and sent before sending any output (with echo or any other method).
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
danbradster
-


Joined: 07 Jul 2006
Posts: 1

PostPosted: Fri Jul 07, 2006 1:26 am    Post subject: Reply with quote

You can use ob_start(); at the top of your code instead of having the header first.
Back to top View user's profile Send private message
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Fri Jul 07, 2006 3:08 am    Post subject: Reply with quote

Server seems to be offline at the moment. Bummer!
-------------------------
BTW, this is the first month of hosting my sig (picture below) and it has received over 2700 hits! Awesome!
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group