Page 1 of 1

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

Posted: Wed Sep 09, 2009 3:35 am
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!

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

Posted: Wed Sep 09, 2009 4:38 am
by jazz090
remove the status header and use absolute paths and it will work.

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

Posted: Wed Sep 09, 2009 6:03 am
by danSM
Top man Jazz that works fine.

So it seems it was the Status header which was breaking it.

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

Posted: Wed Sep 09, 2009 6:07 am
by jazz090
yes