$fullurl = $_SERVER['FULL_URL'];
if (!strpos($fullurl, 'http://www.'))
{header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.mysite.com/"); }
it just keeps reloading the page on a loop. :(
I assume because your second header line is OUTSIDE the if block
@jacen.. Its all fine still, He has brackets around it doesn't mater.
@k_talk
http://php.net/strpos
From what php.net says I don't think you should use that..
Try:
if (eregi('http://www.', 'http://'.$_SERVER["HTTP_HOST"]))
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.mysite.com/");
}
http://php.net/eregi
:D
Isn't the tabs important for PHP? (the space, whatever)
no.. in fact php ignores whitespace unless you have it in "".
The spacing and all is just for normal human readability (im not normal so I can read it like php does)
Fair enough.
Lainaus käyttäjältä: k_talk - joulukuu 08, 2006, 09:15:26 IP
$fullurl = $_SERVER['FULL_URL'];
if (!strpos($fullurl, 'http://www.'))
{header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.mysite.com/"); }
it just keeps reloading the page on a loop. :(
Using eregi for this is a huge overkill. It's really much slower.
Use:
$fullurl = $_SERVER['FULL_URL'];
if (strpos($fullurl, 'http://www.') === false)
{header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.mysite.com/"); }
The reason is that the strpos returns the position of the string which is 0 if the search string starts with the searched one. And (!0) is still true. So it keeps reloading the page.
Strpos returns "false" if the string is not found,
=== will check if the values are equal and of the same type - boolean in this case.