Parašė Edvinas.· 2009 Rugs. 15 15:09:00
#16
Sita i Index.php ar koks pas tave
<?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/>";
?>
Sita i Onlline.php
<?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();
}
?>
Sitas SQL Table
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;
Redagavo Edvinas.· 2009 Rugs. 15 15:09:28