How to store visitors ip in database and recall it >> if they visit again with same ip they redirect to home page>> and this ip should delete from database in 24hrs..
can anyone try to make this code..?
can anyone try to make this code..?
CREATE TABLE `logs` ( `id` bigint(1000000) NOT NULL auto_increment, `ip` varchar(15) NOT NULL, `time` int(10) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
$where = ''; // Where to redirect
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
if (!empty($ip)) {
$time24 = (time() - (24 * 60 * 60));
$check = mysql_query('SELECT COUNT(*) FROM `logs` WHERE `ip` = "'.$ip.'" AND `time` < '.$time24.'');
if (!mysql_num_rows($check)) {
@mysql_query('INSERT INTO `logs` VALUES (\'\', "'.$ip.'", "'.time().'")');
// The rest of page goes here...
} else {
$select = mysql_query('SELECT `id` FROM `logs` WHERE `time` > '.$time24.'');
if (mysql_num_rows($select)) {
while ($sel = mysql_fetch_array($select)) {
@mysql_query('DELETE FROM `logs` WHERE `id` = '.$sel[0].'');
}
}
header('Location: '.$where.'');
exit;
}
} else {
exit('No IP...');
}
function logs() {
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
if (!empty($ip)) {
$time24 = (time() - (24 * 60 * 60));
$check = mysql_query('SELECT COUNT(*) FROM `logs` WHERE `ip` = "'.$ip.'" AND `time` < '.$time24.'');
if (!mysql_num_rows($check)) {
@mysql_query('INSERT INTO `logs` VALUES (\'\', "'.$ip.'", "'.time().'")');
return false;
} else {
$select = mysql_query('SELECT `id` FROM `logs` WHERE `time` > '.$time24.'');
if (mysql_num_rows($select)) {
while ($sel = mysql_fetch_array($select)) {
@mysql_query('DELETE FROM `logs` WHERE `id` = '.$sel[0].'');
}
}
return true;
}
} else {
return true;
}
}
//
if (logs())
header('Location: http://google.com/');
exit;
Comment