Forum Moderators: coopster
When you set a cookie with setcookie(), the corresponding $_COOKIE["name"] is not available within that instance of the script because all it has done is set the headers. $_COOKIE only contains cookies that were sent with the page request, which is why it is empty the first time through but there on the next page view.
It sounds like you want to be doing something like this instead:
if ($_COOKIE["someVariable"])
{
$someVariable = $_COOKIE["someVariable"];
}
else
{
$someVariable = "Default Value"
}
setcookie("someVariable",$someVariable);
...This way, you only access $_COOKIE[] once at the top of your script, and then use $someVariable throughout the rest of your code...