Hi!
What I try to do is this:
A user comes to my page. If he visits for the first
time he get's cookies containing a unique user-number,
number of vistits, and last vistit. The information is also
stored in a db.
If he comes back to the site (at least more than an hour
after his last visit) this information is used and the db updated.
What I do:
If a user has the cookies I update the db, if he has
no cookies I create a db row with his new
user-number and set the cookies
This however means that if a browser is not
cookie enabled it will provoke a new user-number entry
in the db for each visit, rendering the efforts of user
stats with this system futile.
So I need to check if the browser is cookie enabled:
2 ways come to mind:
a.) check if the cookievars are set and if they're
not, then...-> This does not work for me since
if the vars are not set i create a new db entry - which
is what I want to avoid, for somebody not cookie enabled
who would create multiple entries
b.) YOUR WAY. If you have any ideas how to
check if a browser is cookie enabled other than a.)
or b.) so I can ignore those users for the stats,
I'd be very happy.
Here's the code I got so far:
<?php
$onehour = date("YmdHi",time()+21480);
// This var I use to determine if the last vistit
//of the page is at least an hour in the past.
//The time + value is conditioned by the time
//difference between my location and the server
if (isset($k_user)&&($n_visit<$onehour))
{
$v_new = $k_visits + 1;
$last_v = date("YmdHi",time()+21600);
$cook = "UPDATE k_user SET " . "visits='$v_new', " . "lastvisit='$last_v'" .
"WHERE user='$k_user'";
mysql_query($cook);
setcookie("n_visit",$last_v, time()+2592000);
setcookie("k_visits",$v_new, time()+2592000);
setcookie("k_user",$k_user, time()+2592000);
}
if (!isset($k_user))
{
$result_cook = mysql_query("SELECT *
FROM k_user ORDER BY id");
$number = mysql_num_rows($result_cook)+1;
$last_v = date("YmdHi",time()+21600);
$cook_new = "INSERT INTO k_user SET " . "user='$number', " . "visits='1', " .
"lastvisit='$last_v', " . "since='$last_v'";
mysql_query($cook_new);
setcookie("k_user",$number, time()+2592000);
setcookie("k_visits","1", time()+2592000);
setcookie("n_visit",$last_v, time()+2592000);
}
?>