Uutiset:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu
Advertisement:

whats the problem with this code?

Aloittaja kL, joulukuu 08, 2006, 09:15:26 IP

« edellinen - seuraava »

kL


$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. :(

Jacen

I assume because your second header line is OUTSIDE the if block
"I've always found that sticking your fingers in your ears and humming loudly solves a whole slew of problems."

SleePy

@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
Jeremy D ~ Site Team / SMF Developer ~ GitHub Profile ~ Join us on IRC @ Libera.chat/#smf ~ Support the SMF Support team!

Jacen

Isn't the tabs important for PHP? (the space, whatever)
"I've always found that sticking your fingers in your ears and humming loudly solves a whole slew of problems."

SleePy

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)
Jeremy D ~ Site Team / SMF Developer ~ GitHub Profile ~ Join us on IRC @ Libera.chat/#smf ~ Support the SMF Support team!

Jacen

"I've always found that sticking your fingers in your ears and humming loudly solves a whole slew of problems."

Rudolf

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.
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

Advertisement: