Forum Moderators: coopster

Message Too Old, No Replies

Rediect loop Problems

problem with redirect loop in firefox

         

danpink

2:43 pm on Apr 3, 2009 (gmt 0)

10+ Year Member



I'm new to PHP and am having problems with what should be very simple code. hopefully someone can help!? please excuse the formatting.

i am getting a redirect loop error code if i access this page in firefox and infinite loop with no error code if i access this page on IE:


<?php

if (!strpos(strtolower($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT']),"playstation portable"))
{
header("location: ./index.php");
}
else {
header("location: ../index.php");
}

?>

the following is the code in the target page im trying to redirect to if device is NOT a psp (../index.php):


<?php

if(strpos(strtolower($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT']),"playstation portable") ){
header("location: ./psp/index.php");}

if(strpos(strtolower($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT']),"playstation 3") ){
header("location: ./ps3/index.php");}

if(strpos(strtolower($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT']),"nintendo wii") ){
header("location: ./wii/index.php");}

if(strpos(strtolower($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT']),"midp") ){
header("location: ./wap/index.php");}
?>

Can anyone see where i'm going wrong?

eeek

9:54 pm on Apr 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



1. The URL in a Location header should be absolute.

2. Your if won't trigger if the strpos() returns 0 for the location (you need to check for not equal to boolean false).

3. You're lucky "location:" works. It should be "Location:".

danpink

11:43 pm on Apr 3, 2009 (gmt 0)

10+ Year Member



thanks for the tips, i have corrected this and discovered a major flaw in the code... the target Location: was pointing to /psp/index.php and not ../index.php - doh!

with that changed it seems to work a treat!