Condition redirect not working any insights??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jhunter@ucb.co.uk
Forum Newbie
Posts: 1
Joined: Mon Sep 26, 2005 9:49 am

Condition redirect not working any insights??

Post 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 ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

A new header cannot be sent after HTML code had been printed.
ruchit
Forum Commoner
Posts: 53
Joined: Mon Sep 26, 2005 6:03 am

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply