Jump to content

re Online users


noobstar

Recommended Posts

Hi there :)

Sorry for re-posting this but this has driven me crazy lol

It's regards how to determine who is online on the site at a present moment. I've had a look at a forum to give me an idea cause i've never done anything like this so far :S

What they do is store the IP address as soon as a person enters the web site into a database table, but what's puzzling me is how would i go about making the database entry (the stored IP address) expire (so it gets deleted from the database after 10-20min).

It's probably something really simple and stupid but i have 0 experience in this area :S

Thank you for any help what so ever! What ever ideas/suggestions you have please let me know :)
Link to comment
https://forums.phpfreaks.com/topic/35760-re-online-users/
Share on other sites

Sorry for the trouble but i solved it Finally might i add haha

This is how i did it just as a record:

[b]First i created a new table in my database:[/b]
[code]CREATE TABLE `forum_online` (
  `online_id` int(100) NOT NULL auto_increment,
  `online_ip` varchar(15) NOT NULL default '0',
  `online_time` int(40) NOT NULL default '0',
  PRIMARY KEY  (`online_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;[/code]

[b]Then i added this code into my index.php:[/b]
[code]$o_ip = getenv('REMOTE_ADDR');
$o_time = time();
$o_query = mysql_query("select * from forum_online") or die('' . mysql_error());
$online = mysql_fetch_assoc($o_query);
$q_timecheck = mysql_query("select * from forum_online where online_ip = '$o_ip'") or die('' . mysql_error());
$timecheck = mysql_fetch_assoc($q_timecheck);
if($timecheck['online_time'] + 1800) // after 30min it deletes the record
{
mysql_query("delete from forum_online where online_ip = '$o_ip'") or die('Error in delete query ' . mysql_error());
}
if($o_ip == $online['online_ip']) // checks to see if the ip address exists
{
// if the record exists do nothing
}
else // otherwise insert ip and current time into table
{
mysql_query("INSERT INTO `forum_online` (`online_id`, `online_ip`, `online_time`) VALUES ('', '$o_ip', '$o_time')") or die('Error in insert query' . mysql_error());
}[/code]


I hope it helps some people around here :)
Link to comment
https://forums.phpfreaks.com/topic/35760-re-online-users/#findComment-170196
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.