noobstar Posted January 26, 2007 Share Posted January 26, 2007 Hi there :)Sorry for re-posting this but this has driven me crazy lolIt'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 :SWhat 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 :SThank 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 More sharing options...
noobstar Posted January 26, 2007 Author Share Posted January 26, 2007 I found a way to do it which is by making field that creates a timestamp for the perticular ip address but how do you go about telling it something in this nature:[b]If timestamp is 10min past ip address deleteend if[/b] ??? Link to comment https://forums.phpfreaks.com/topic/35760-re-online-users/#findComment-169486 Share on other sites More sharing options...
trochia Posted January 26, 2007 Share Posted January 26, 2007 > (so it gets deleted from the database after 10-20min). After ot is first recorded?.. or 10 mins after they log out...very vague on what you want to do, as why even record it then?.. As with a db...you logging - recording for data anyway ? Link to comment https://forums.phpfreaks.com/topic/35760-re-online-users/#findComment-169584 Share on other sites More sharing options...
noobstar Posted January 26, 2007 Author Share Posted January 26, 2007 Sorry for the trouble but i solved it Finally might i add hahaThis 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.