Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cookie incrementing

Status
Not open for further replies.

mwpclark

Programmer
Mar 14, 2005
59
0
0
US
Hi

This may not be the forum for cookies, but a search brought up several different forums, so since it is written in php here is my question:
Code:
if ($catid != "index") {
$oldCookieValue = $_COOKIE[$catid];
if ($oldCookieValue == "") {$oldCookieValue = 0;}
$cookieValue = $oldCookieValue + 1;
setcookie($catid, $cookieValue, NULL, '/');
}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
This sets a cookie for each category (catid) and increments by one each time the page is loaded. The code is in a header.php page that is included by all pages on the site.

The problem is that sometimes it starts at 2. Each page is linked from the index page, which does not set a cookie. When I use *http live headers* it shows the cookie value setting at 1. But when I view cookies in firefox, some of them are 1 and some are 2. There is no further code regarding cookies in any of the pages, it is only called once in the header file. The $catid values are unique, no duplicates.

I understand cookie behavior can be random. This seems to occur in opera also. The site uses url rewrite heavily, but I don't see that in live headers so I don't *think* that is relevant.

Any ideas?

Thanks
Mike
 
Hi

Mike said:
I understand cookie behavior can be random.
Wrong.
Mike said:
The site uses url rewrite heavily, but I don't see that in live headers so I don't *think* that is relevant.
Correct.

And what is you web server's access log saying ? How many times were those pages requested ?

Feherke.
 
The server access log count agrees with how many times I viewed the page. If I viewed once it appears once from my IP. But with firefox show cookies, some pages show a cookie value of 2 and others show 1.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top