Weird Cookie Problem

This is kinda tough to describe.

  1. I have a jump menu on a page.
  2. The url var set by the Jump menu should set/change a cookie
  3. What’s happening, as I click through the Jump menu, is that the cookie value is always ONE BEHIND the actual URL var.

[php]

if(isset($_GET[“calid”])) {
setcookie (“cookie_CalID”, “”, time() - 3600); // clear out the old value
setcookie(“cookie_CalID”, $_GET[“calid”]); }

  echo  "COOKIE =".$_COOKIE["cookie_CalID"]."<br>";	
  echo "URL = ".$_GET["calid"];	

[/php]

So, for the urls below, the code above will show:

  1. mypage.php?calid=2
    … Cookie = (whatever the default value is)
    … URL = 2

  2. mypage.php?calid=3
    … Cookie = 2
    … URL = 3

  3. mypage.php?calid=4
    … Cookie = 3
    … URL = 4

  4. mypage.php?calid=2
    … Cookie = 4
    … URL = 2

What the heck??? Ideas?

I changed from a cookie to a session variable:

[php]// if(isset($_GET[“calid”])) {
if($_GET[“calid”] != ‘’) {
$_SESSION[‘sess_CalID’] = $_GET[“calid”]; }

  echo  "COOKIE =". $_SESSION['sess_CalID']."<br>";	
  echo "URL = ".$_GET["calid"];	[/php]

Now it works EXACTLY like it’s supposed to.
I still have no clue as to why it wasn’t working properly with a cookie though. No ideas?

Sponsor our Newsletter | Privacy Policy | Terms of Service