function ip_tracker_user_save in IP address manager 6
Same name and namespace in other branches
- 7.2 ip.module \ip_tracker_user_save()
- 7 ip.module \ip_tracker_user_save()
Save a record into the ip_tracker table.
File
- ./
ip.module, line 92 - IP address manager module.
Code
function ip_tracker_user_save($uid) {
// Check to see if a row exists for this uid/ip combination.
$sql = "SELECT visits FROM {ip_tracker} WHERE uid = %d AND ip = %d";
$args = array(
$uid,
ip2long(ip_address()),
);
$visits = db_result(db_query($sql, $args));
if ($visits) {
// Update.
$sql = "UPDATE {ip_tracker} SET visits = %d, last_visit = %d WHERE uid = %d AND ip = %d";
$args = array(
$visits + 1,
time(),
$uid,
ip2long(ip_address()),
);
db_query($sql, $args);
}
else {
// Insert.
$sql = "INSERT INTO {ip_tracker} (uid, ip, visits, first_visit, last_visit) VALUES (%d, %d, 1, %d, %d)";
$args = array(
$uid,
ip2long(ip_address()),
time(),
time(),
);
db_query($sql, $args);
}
}