Here you go:
<?php
$dbcon = mysql_pconnect("host","username","password");
@mysql_select_db("database",$dbcon);
//expiration of 1 year
$exp = time() + (606024*365);
function update_hits() {
global $this_page_id;
$q = "SELECT COUNT(*) FROM hits WHERE page_id='$this_page_id'";
$r = mysql_query($q);
$n = mysql_fetch_row($r);
if($n[0] < 1) {
$q = "INSERT INTO hits (page_id, hits) VALUES ('$this_page_id', '1')";
}
else {
$q = "UPDATE hits SET hits=hits+1 WHERE page_id='$this_page_id'";
}
if(!mysql_query($q)) {
return mysql_error();
}
else {
return 0;
}
}
if(!$visit_data) {
if(update_hits()) {
echo "an error has occured! ".mysql_error();
die();
}
else {
setcookie("visit_data[0]",$this_page_id,$exp);
}
}
else {
if(!in_array($this_page_id,$visit_data)) {
if(update_hits()) {
echo "an error has occured! ".mysql_error();
die();
}
else {
$num_visit_data = count($visit_data);
$next_visit_data_id = $num_visit_data + 1;
setcookie("visit_data[$next_visit_data_id]",$this_page_id,$exp);
}
}
}
?>
I hope this gets you on your way. I tested it for you and it works just fine.
Chad.