Forum Moderators: coopster

Message Too Old, No Replies

Stuck in a redirect loop

Trying to catch id, set cookie, then use a 301 redirect

         

Jeremy_H

4:35 pm on May 12, 2006 (gmt 0)

10+ Year Member



Help! I'm stuck in a loop.

I'm using an incoming URL with a special country code attached. If the code is defined and valid, the code is stripped off and set to a cookie, and then 301 redirected to the same page, but without the attached code.

Then, if the page loads without an attached code, the script looks for a country cookie. If there is a cookie found, it loads up one way based on that country. If no cookie is found, it loads up with the United States as default.

The problem is, I'm stuck in a loop. If no country code is defined, then the page loads up great. However, if a country code is defined, then it never stops.

Here's the relevant code:

*****

$iso=array("dz","ao");

if((isset($_REQUEST["c"]))&&(in_array(strtolower($_REQUEST["c"]),$iso))){
setcookie("c",strtolower($_REQUEST["c"]),time()+60,"/",".example.com");
header("HTTP/1.1 301 Moved Permanently");
header("Location:http://www.example.com/folder/");
}

elseif(isset($_COOKIE["c"])){
$c=$_COOKIE["c"];
if($c=="dz"){
$c=array("dz","Algeria","Algerian",1);
}
else{
$c=array("ao","Angola","Angolan",1);
}
}

else{
$c=array("us","United States","American",7);
}
*****

Incoming links would either look like this:
example.com/folder/
example.com/folder/?c=dz
example.com/folder/?c=ao

Thanks for any help

jatar_k

4:45 pm on May 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> If no country code is defined, then the page loads up great. However, if a country code is defined, then it never stops

when you say defined do you mean 'in the url'

have you tried using GET instead of REQUEST?

Jeremy_H

8:27 pm on May 12, 2006 (gmt 0)

10+ Year Member



Thank you, the GET works great.