Weird PHP header issue, works on localhost, but not with ip

hitokiri

Limp Gawd
Joined
Jan 1, 2001
Messages
178
I'm currently writing a few pages and within some pages I have the following header to redirect in certain cases:

Code:
ob_end_clean();
	
header("Location: http://" . $_SERVER['HTTP_HOST'] . 
dirname($_SERVER['PHP_SELF']) . "/index.php");

exit();

This code works perfect when i'm accessing it through http://localhost/current_page and it will redirect me back to http://localhost/index.php

However, if i'm accessing it through a ip address such as http://ip_address/current_page it will try to redirect me to http://ip_address\/index.php and of course that's a invalid url and it get the page cant be found issue.

I have not changed any code for this to happen, any ideas where or why that backslash comes from?

Also when I do a phpinfo(); the superglobal contents comes up correct for localhost and the ip_address... so I currently have no clue as to where that \ came from. As for the webserver i'm using, i'm currently using Apache 2.0.55.

Thanks

- hito
 
Wouldn't hapeen to be running on Windows would it? http://us2.php.net/manual/en/function.dirname.php#54868

Doesn't say a fix, but someone else that had that problem. You could a check on the last character of the string and remove it if it's a '\'.

edit: A search for Windows on that same page gives a few suggestions. If it is in fact a Windows issue - quite a bit of a posts on there about Windows messing with the slashes.
 
Yes, I am actually running it on a windows machine. Thank you for the link, I will read up on that right away, thank you :)
 
Back
Top