PDA

Click to See Complete Forum and Search --> : Simple counter


evil_gamer
Jun 26th, 2002, 09:14 PM
I am working on a simple counter.

When the page is hit, a file is opened and records the hit (an invisible counter). However, I wish to prevent the counter from counting reloads but I don't want to use cookies. Is this possible? Or would I have to use sessions or stuff like that?

The Hobo
Jun 27th, 2002, 10:16 AM
Originally posted by evil_gamer
I am working on a simple counter.

When the page is hit, a file is opened and records the hit (an invisible counter). However, I wish to prevent the counter from counting reloads but I don't want to use cookies. Is this possible? Or would I have to use sessions or stuff like that?

You'd probably have to use cookies to store whether or not the user has been counted. Or you could record their IP addresses (but dialup IPs don't stay the same)

You could even use sessions and track their session id, but sessions use cookies to work.

filburt1
Jul 1st, 2002, 08:47 PM
If you do track their IP, you probably want to chop off the last digit grouping. The reason? Many DHCP broadband companies change your IP but that last grouping, and it's rare that somebody else from within that grouping will get miscounted just given the traffic of the site.

Iamryan2002
Jul 1st, 2002, 09:29 PM
sessions are easier and are stored on the server, not the client...


<?
session_start(); // this is what starts it all... before html!

if(!$logged) //check if a session is here
{
$logged = 1; // no session found...
session_register(logged); // make one ;)
}
else
{
// counter code here!
}
?>


simple example.... this will work nicely.. that way you have no worries.....

The Hobo
Jul 1st, 2002, 11:01 PM
Originally posted by Iamryan2002
sessions are easier and are stored on the server, not the client...


<?
session_start(); // this is what starts it all... before html!

if(!$logged) //check if a session is here
{
$logged = 1; // no session found...
session_register(logged); // make one ;)
}
else
{
// counter code here!
}
?>


simple example.... this will work nicely.. that way you have no worries.....

But sessions use cookies (to track the session ID), so why not just use cookies to track whether or not they've been counted and skip the session crap? Makes more sense to me.

The Hobo
Jul 1st, 2002, 11:11 PM
And just incase you want to argue that they don't use cookies:

A visitor accessing your web site is assigned an unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.

Of course you can store it in the URL, but once they close the window, it's gone. Next time they come back, they're assigned a new session ID.

Iamryan2002
Jul 2nd, 2002, 12:52 PM
either way...

The Hobo
Jul 2nd, 2002, 01:11 PM
Originally posted by Iamryan2002
either way...

What do you mean, either way? Sessions would need cookies to work, so if you're going to use cookies, why not just store it in the cookie?

Iamryan2002
Jul 2nd, 2002, 01:38 PM
I realize that sessions use cookies...

for a counter though, sessions are better... while you are at the site you are only one count, right.. well when you leave, the session is destroyed. You come back you are counted again.

Sessions will give you a much more accurate count, not cookies..

The Hobo
Jul 2nd, 2002, 04:30 PM
Originally posted by Iamryan2002
I realize that sessions use cookies...

for a counter though, sessions are better... while you are at the site you are only one count, right.. well when you leave, the session is destroyed. You come back you are counted again.

Sessions will give you a much more accurate count, not cookies..

That's not counting unique visitors then...

The Hobo
Jul 2nd, 2002, 04:36 PM
Off the top of my head, for daily uniques:


if (is_set($_COOKIE["countdate"])) {
if ($_COOKIE["countdate"] != date("m.d.y") {
//count the person for today
setcookie("countdate", date("m.d.y");
}
} else {
setcookie("countdate", date("m.d.y");
//count the person for today
}

Iamryan2002
Jul 3rd, 2002, 07:09 PM
that would work also... sessions, cookies, all good

The Hobo
Jul 3rd, 2002, 11:08 PM
Originally posted by Iamryan2002
that would work also... sessions, cookies, all good

shut up