Hi Jack,
I choose to modify the code, instead of changing the primary key. I keep the ip column as the primary key, but from the code I change the format in ip column to be “$ip/$tanggal”, so new entry will be recorded if the same ip is visiting in different date (tanggal). For me, this way works well and fix the counter stop issue. In my case, I only need information about Today Visit, Yesterday, Total Visit, and Total Hints. I’m not sure about other stuff, but if anybody wanna give a try, follow this:
Find these lines:
// Check your IP, whether the user has had access to today's
$sql = mysql_query("SELECT * FROM <code>". BMW_TABLE_NAME . "</code> WHERE ip='$ip' AND tanggal='$tanggal'");
// If not there, save the user data to the database
if(mysql_num_rows($sql) == 0){
mysql_query("INSERT INTO <code>". BMW_TABLE_NAME . "</code>(ip, tanggal, hits, online) VALUES('$ip','$tanggal','1','$waktu')");
}
else{
mysql_query("UPDATE <code>". BMW_TABLE_NAME . "</code> SET hits=hits+1, online='$waktu' WHERE ip='$ip' AND tanggal='$tanggal'");
}
and then replace with
// ---- modified by parasatria.me
// Get ipx = ip + tanggal, as new format for primary key
$ipx = $ip."/".$tanggal;
// Check if the ip has ever visit before
$sql = mysql_query("SELECT * FROM <code>". BMW_TABLE_NAME . "</code> WHERE ip='$ip'");
// if never visit us before, check the ipx
if (mysql_num_rows($sql) == 0){
// Check if the ipx has ever visit before
$sql3 = mysql_query("SELECT * FROM <code>". BMW_TABLE_NAME . "</code> WHERE ip='$ipx'");
// if the ipx never visit us before, add new entry with new format key, else update entries
if (mysql_num_rows($sql3) == 0){
mysql_query("INSERT INTO <code>". BMW_TABLE_NAME . "</code>(ip, tanggal, hits, online) VALUES('$ipx','$tanggal','1','$waktu')");
} else {
mysql_query("UPDATE <code>". BMW_TABLE_NAME . "</code> SET hits=hits+1, online='$waktu' WHERE ip='$ipx'");
}
} else {
// Check if the ip was visiting at the same date
$sql2 = mysql_query("SELECT * FROM <code>". BMW_TABLE_NAME . "</code> WHERE ip='$ip' AND tanggal='$tanggal'");
// if it's not at the same date, check the ipx, else update entries
if (mysql_num_rows($sql2) == 0){
// Check if the ipx has ever visit before
$sql3 = mysql_query("SELECT * FROM <code>". BMW_TABLE_NAME . "</code> WHERE ip='$ipx'");
// if the ipx never visit us before, add new entry with new format key, else update entries
if (mysql_num_rows($sql3) == 0){
mysql_query("INSERT INTO <code>". BMW_TABLE_NAME . "</code>(ip, tanggal, hits, online) VALUES('$ipx','$tanggal','1','$waktu')");
} else {
mysql_query("UPDATE <code>". BMW_TABLE_NAME . "</code> SET hits=hits+1, online='$waktu' WHERE ip='$ipx'");
}
} else {
mysql_query("UPDATE <code>". BMW_TABLE_NAME . "</code> SET hits=hits+1, online='$waktu' WHERE ip='$ip' AND tanggal='$tanggal'");
}
}
// ---- end of modification, by parasatria.me