op vele websites zie je dit tegenwoordig.Ik bedoel het aantal gebruikers dat op de site zit. hoe doen die da ? simpel
Code: Selecteer alles
<?php
$server="localhost";
$db_user="mysql_user";
$db_pass="mysql_pass";
$db="databasename";
$ip=$_SERVER['REMOTE_ADDR'];
$timeoutseconds=300;
$timestamp = time();
$timeout=$timestamp-$timeoutseconds;
mysql_connect($server,$db_user,$db_pass) or die (mysql_error());
mysql_select_db($db);
$insert=mysql_query("INSERT INTO useronline VALUES ('$timestamp','$ip','$PHP_SELF')");
if(!$insert){
die("useronline insert failed");
}
$delete=mysql_query("DELETE FROM useronline WHERE timestamp<$timeout");
if(!$delete){
die("could not delete information from the database");
}
$result=mysql_query("SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'");
if(!$result){
die("database selection error");
}
$user=mysql_num_rows($result);
mysql_close();
if($user ==1) {
print("<b>$user</b>user online\n");
}else{
print("<b>$user</b> users online\n");
}
?>
dan moet je een MySQL database table maken
Code: Selecteer alles
CREATE TABLE useronline (
timestamp int(15) DEFAULT '0' NOT NULL,
ip varchar(40) NOT NULL,
file varchar(100) NOT NULL,
PRIMARY KEY (timestamp),
KEY ip (ip),
KEY file (file)
);
in elk bestand dat je nu de aantal gebruikers wilt tonen dat online is op de site voeg je dit bestand in eg
Code: Selecteer alles
<?php include("filename.php") ?>
voila ....