View Single Post
  #1  
Old 29th June 2010, 10:50
Hasan Hasan is offline
Senior Member
 
Join Date: Apr 2010
Denmark
Posts: 29
Default Guest Online/log Script!
A little script I made..( Used codes from other script and made this)
I'm still new too php so please be gentle o.o


In this script you can see guest/user online last 5 mins(you can chose how long time as well)and there will be added a log too..

You can see how it looks in my side wwww.u-torrentz.org, Just scroll down.

1) Install the Sql ( remember to change CHARSET to "latin1" when you import the sql file)

Code:
Code:
CREATE 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;
2) Upload the online.php file in you root ( You can mod it and add so you can see ip by adding "ip" or do other mods o.o)

3)

Add this code where ever you want it to... (easily too mod)

Code:
                
        //Guest Online
        $db_host = "localhost";
        $db_user = "User-name"; 
        $db_pass = "Password";
        $db_name = "DATABASE";
        $dbc = mysql_connect($db_host, $db_user, $db_pass);
        $dbs = mysql_select_db($db_name);
        $tm = time();
        $timeout = $tm - (300);  //300 is 5 mins
        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("INSERT INTO guest SET  time='".$tm."', ip='".$ip."', browser='".$browser."'");
        $delete = mysql_db_query($db_name, "DELETE FROM guest WHERE time<$timeout"); 

if(!($delete)) { 

    print ""; 

} 

        $count = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM guest"));
        mysql_close();
        echo "<br/><a href=\"online.php\"><b>Total Guest Online In Last 5 mins:</b> $count[0]</a><br/>";
Here you go :d
Attached Files
File Type: php online.php (835 Bytes, 18 views)
File Type: sql guest.sql (214 Bytes, 11 views)
Reply With Quote
The Following 2 Users Say Thank You to Hasan For This Useful Post:
Baba (25th March 2020), Fynnon (29th June 2010)