Hey guys, I'm modifying a classified site, it's written in PHP.
What I'm trying to do is when a user comes in the website for the first time (aka no cookies created) the value of the variable would be -1, when they click on a state to browse in, it will have ?statechosen=1&blahblah, so the value would be 1 for a variable, and if its 1 it won't ask for the states again, it will only ask for the states when its -1, or 0.
but it's weird.
i have to click on the name of the state twice to have the cookie settings in effect. And if i go on the index page twice, it'll ask me to choose the state again.
here's the code.
<?php $country_url = "?statechosen=1&cityid=-$country[countryid]&lang=$xlang;" ?>
function xSetCookie($name, $value)
{
setcookie($name, $value, 0, "/");
}
setcookie($ck_choosestate, $xstatechosen, time()+(60*24*60*60), "/");
$xstatechosen ="";
$statechosen ="";
$ck_choosestate = "xzclf_choosestate";
//Choose State
$nostate = -1;
if ($_GET['statechosen'] > 0)
{
$xstatechosen = $_GET['statechosen'];
}
elseif ($_GET['statechosen'] < 0)
{
$xstatechosen = $_GET['statechosen'];
}
elseif ($_COOKIE[$ck_choosestate] > 0)
{
$xstatechosen = $_COOKIE[$ck_choosestate];
}
elseif ($_COOKIE[$ck_choosestate] < 0)
{
$xstatechosen = $_COOKIE[$ck_choosestate];
}
elseif ($nostate)
{
$xstatechosen = $nostate;
}