asglu 0 Report post Posted July 22, 2008 (edited) make an index.php copy and paste this code <?php$db_host = "localhost";$db_user = "root";$db_pass = "";$db_name = "test";$dbc = mysql_connect($db_host, $db_user, $db_pass);$dbs = mysql_select_db($db_name);$tm = time();$timeout = $tm - (30*60); if($_SERVER["REMOTE_ADDR"]){$ip=$_SERVER["REMOTE_ADDR"];}else{$ip=$_SERVER["HTTP_X_FORWARDED_FOR"];}$brws = explode("(",$_SERVER["HTTP_USER_AGENT"]);$browser = $brws[0];mysql_query("DELETE FROM guest WHERE actvtime <'".$timeout."'");mysql_query("INSERT INTO guest SET time='".$tm."', ip='".$ip."', browser='".$browser."'");$count = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM guest"));mysql_close();echo "<br/><a href=\"online.php\">Users Online($count[0])</a><br/>"; ?> the make online.php .copy and paste this code in it<?php$db_host = "localhost";$db_user = "root";$db_pass = "";$db_name = "test";$dbc = mysql_connect($db_host, $db_user, $db_pass);$dbs = mysql_select_db($db_name);$result = mysql_query("SELECT time ,ip ,browser FROM guest ORDER BY time ")or die(mysql_error());while($row = mysql_fetch_array($result)){echo "$row[1] $row[2] ";$newtime =$row[0]+(0 *60 *60); echo "<b>".date("D d M y - H:i:s",$newtime)."</b><br/>"; echo "------------<br />";mysql_close();}?> SQL tableCREATE TABLE `guest` ( `time` int(15) NOT NULL default '0', `ip` varchar(50) NOT NULL default '', `browser` varchar(50) NOT NULL default '', PRIMARY KEY (`time`))ENGINE=MyISAM DEFAULT CHARSET=latin1; Edited July 22, 2008 by asglu (see edit history) Share this post Link to post Share on other sites
moodsey211 0 Report post Posted July 25, 2008 may i know if what is this code all about? Share this post Link to post Share on other sites
bangms 0 Report post Posted July 25, 2008 I think it tells you how many Guests are online. Share this post Link to post Share on other sites
gogoily 0 Report post Posted August 4, 2008 You can use text file to store the online visitors' information and it can save database resource. Share this post Link to post Share on other sites
iGuest 3 Report post Posted March 20, 2010 Very nice.Php Guest Online ScriptObviously, one has to adjust all formatting and stuff to suit their own site, but I find this script-set to be quite awesome. It's potent and extensible and also I quite like the backward compatibility: allowing for "http_x_forwarded_for" as well as "remote_addr". The SQL table needed is simple, as well. Before I saw this script, I was under the impression that one needed to incorporate a "Cron Job" to regularly check session vars contained in a user table that included both registered and guest entries. Some hosting services provide means to create a "Cron Job", others you need to configure yourself. Either way, I didn't realize that a simple time comparison could do the same trick. I'm still adapting this script for use on my own site (personal) but my intent is to simply track how many people are checking out the site at any given time. My site doesn't have any type of user registration, not even a forum. Like I said it's a "bujois" personal site, and honestly the little "network" is less than 30 strong. No user system needed ...No one's asked for features or anything. Again this is a really nice and simple script (with little overhead, I might add) for use for displaying guests, or in my case just "X Users Viewing". Thanks for posting it, didn't find anything nearly as efficient as this. Everything else I found was far too complex and had too many bells and whistles to shave down all but the essentials. Rawk on!-reply by Vince Share this post Link to post Share on other sites