header("Location:") not working on Windows server? Help!

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
danSM
Forum Newbie
Posts: 2
Joined: Wed Sep 09, 2009 3:25 am

header("Location:") not working on Windows server? Help!

Post by danSM »

Hi there,

I hope someone can help me with this problem.

I have written a very simple PHP redirect script for a language selection page. It receives a language submitted from an HTML form and uses it to redirect using the header(Location"") function. The site is hosted on a Windows server with a well known UK hosting company.

The script is as follows:

Code: Select all

 
<?PHP
/*
PHP to redirect country based on selection
*/
 
//Get the information sent in from the language selection
$language = $_POST['sel_lang'];
 
//Save the URL
$url = "../lang/".$language."/welcome.htm";
 
//Bounce to the correct page
header("Status: 200");
header("Location: $url");
?>
 
I have tried echoing the link and the variable as HTML and they are as expected (echoing an <a href=""> of the link works fine when clicked). Also, if I take the same files and drop them onto a Linux server they work fine. However, on the Windows server the page just stays blank. I have contacted the hosting company who say there is an error with my script. I really hope I there isn't one staring me in the face but I can't see why such a simple script would have any errors?

I did put the entire URL (http://www. etc) into the $url variable, but I have removed it for now so that it can't be found on this forum page.

Could someone please have a look to make sure I have not made a stupid mistake, or write if they have heard of such a Windows-specific problem before?

Many thanks!
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: header("Location:") not working on Windows server? Help!

Post by jazz090 »

remove the status header and use absolute paths and it will work.
danSM
Forum Newbie
Posts: 2
Joined: Wed Sep 09, 2009 3:25 am

Re: header("Location:") not working on Windows server? Help!

Post by danSM »

Top man Jazz that works fine.

So it seems it was the Status header which was breaking it.
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: header("Location:") not working on Windows server? Help!

Post by jazz090 »

yes
Post Reply