.
Noch 'was geeklich - Grin with cat attached — LiveJournal
Previous Entry Next Entry
Noch 'was geeklich Apr. 9th, 2002 11:38 am
Is using a cookie to force a webcounter to return 304 for an hour too much of a kludge?

From: ciphergoth
Date: April 9th, 2002 - 04:03 am (Link)
Just looked up 304 - "Not Modified" -

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5

I'm confused, what are you trying to achieve? You want to stick a cookie on people so that they get a 304 when they try and look at the web counter?
From: wechsler
Date: April 9th, 2002 - 04:11 am (Link)
Not on the first time they request it - then it's 200 OK. On subsequent turns there's no reason for it to be sent again - the fact that it *was* getting resent was skewing my webstats.

There *may* be a potential problem if the counter falls from the cache while the cookie's active - I assume it'll just come up as a bad image in this unlikely case.



if(!$noincrement) {
setcookie("noincrement","1",time()+3600);
} else {
header("HTTP/1.0 304 Not Modified");
exit();
}
From: ciphergoth
Date: April 9th, 2002 - 04:31 am (Link)
You should never return a 304 on an unconditional GET.

But if you have enough control over the server to set cookies on people, why do you need a web counter image? Can't you just directly count the loads on each page? If you want to distinguish distinct visits, then sure, cookie people (though you'll always get awkward buggers like me refusing the cookie). But in answer to your question, yes...
From: wechsler
Date: April 9th, 2002 - 04:40 am (Link)
You should never return a 304 on an unconditional GET.
Probably true, but I can't figure how to check if it's conditional.

But if you have enough control over the server to set cookies on people, why do you need a web counter image?
"Cos I want one ;)". I dunno, maybe I don't need it - the only problem is that my weblog parser only counts the last 12 months, and I want a full total.

Can't you just directly count the loads on each page?
That'd count page hits, hopefully the counter can get some idea of visits.

If you want to distinguish distinct visits, then sure, cookie people (though you'll always get awkward buggers like me refusing the cookie).
Fair enough - the site should always work without cookies (unless you're logging in to change data), and I try to keep the cookie names transparent so people can see what they're being offered if the browser supports it.

But in answer to your question, yes...
Well, it still beats working. Wish i could find someone to pay me to tinker with websites.