Page 1 of 1

Condition redirect not working any insights??

Posted: Mon Sep 26, 2005 10:02 am
by jhunter@ucb.co.uk
Ok im a cold fusion person dabling in a little php so alittle help will save me alot of time;

I'm trying to do a redirect from a page http://www.thewordismusic.co.uk to http://www.wordismusic.co.uk/mobile.php if the URL used is http://www.ucbmobile.co.uk

I created the following code after readin a few forums;

<?php if ( $_SERVER["HTTP_HOST"] == 'www.ucbmobile.co.uk')
{header("Location: http://www.thewordismusic.co.uk/mobile.php");}
EXIT;?>

However I get the following error message;

Warning: Cannot modify header information - headers already sent by (output started at D:\Sites\thewordismusic.com\web\index.php:4) in D:\Sites\thewordismusic.com\web\index.php on line 5

Is there a way i can check the host and redirect the page at the same time ?

Posted: Mon Sep 26, 2005 10:04 am
by feyd

Posted: Mon Sep 26, 2005 2:41 pm
by pilau
A new header cannot be sent after HTML code had been printed.

Posted: Mon Sep 26, 2005 11:46 pm
by ruchit
try putting this block of the code on top of the page.. alternatively you can put ob_start(); as the first line of you file... also, i believe that "L" in Location should be changed to "l" but i am not sure if it makes any difference.

Posted: Tue Sep 27, 2005 12:02 am
by feyd
use of output buffering is a band-aid. Fix the problem, don't hide it.

As for Location versus location, Location is the correct name of the header.