Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirection in PHP

Status
Not open for further replies.

Daft

Programmer
Oct 19, 2000
9
BE
Hi,

I search a function in php who's redirect a page to an another ! Can you tell me the name of this function and how I must user it !

Daft
 
Code:
<?php
$new_url = &quot;[URL unfurl="true"]http://www.the_new_url.com/&quot;;[/URL]
header(&quot;Location: $new_url&quot;);
?>

Or
Code:
<?php
header(&quot;Location: [URL unfurl="true"]http://www.the_new_url.com/a_directory/a_file.html&quot;)[/URL]
?>

This must be sent before ANY other output, or the browser will be unable to use it as a header. (of course, any output sent after it will be ignored, also, as the browser redirects)
 
if need to use after send,
add ob_start(); at the very first beginning
 
In addition to what rycamor said, if you're checking for a variable for conditional redirectioning and you have more stuff underneath for nonmatching variables, you can make sure those commands aren't executed by simply adding exit() at the end of your if statement.
 
I've got a question on this topic, how do I redirect based on the URL the vistor used.
ie; opens index.html as usual
but
normally also finds the same index.html, but I want to redirect this user to another page in my site.

Help!

D :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top