# Weird Cookie Problem

**URL:** <https://www.phphelp.com/t/weird-cookie-problem/18969>\
**Category:** General PHP Help\
**Created:** [November 24, 2012, 6:00am UTC](https://www.phphelp.com/t/weird-cookie-problem/18969 "2012-11-24T06:00:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LesMizzell](https://www.phphelp.com/user_avatar/www.phphelp.com/lesmizzell/32/687_2.png) [@LesMizzell](https://www.phphelp.com/u/LesMizzell)\
**Post date:** [November 24, 2012, 6:00am UTC](https://www.phphelp.com/t/weird-cookie-problem/18969/1 "2012-11-24T06:00:03Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![LesMizzell](https://www.phphelp.com/user_avatar/www.phphelp.com/lesmizzell/32/687_2.png) [@LesMizzell](https://www.phphelp.com/u/LesMizzell)\
**Post date:** [November 24, 2012, 4:21pm UTC](https://www.phphelp.com/t/weird-cookie-problem/18969/2 "2012-11-24T16:21:02Z")

</div>

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?
