faqts : Computers : Programming : Languages : PHP : Common Problems : Redirects

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

72 of 107 people (67%) answered Yes
Recently 8 of 10 people (80%) answered Yes


How can I redirect to another URL at any point of my PHP source? For example, using RESPONSE.BUFFER=TRUE at the header in ASP source, I can do that.

Jul 5th, 2002 20:53
Dan Christensen, Henrik Hansen, EAD Centro Universitário Feevale,

an example
if($bla == "true"){
  Header("Location: new_url");
} else {
you can't use header if you print info before useing it
addition from opello:
you can also add
<?php ob_start(); ?>
to the top of your php page (tested in version 4.2.1)
then use header("Location: " . $url); wherever you want.
there are also other ob_ commands that go with this one, they may be 
helpful, search the PHP manual / function and definition list