Online script
Auteur: leendert - 07 augustus 2005 - 17:58 - Gekeurd door: Joel - Hits: 4960 - Aantal punten: (0 stemmen)
Een script waarmee je kan zien hoeveel gasten/leden er online zijn. Ook is te zien welke leden er online zijn:
Dit is de tabel:
CREATE TABLE `online` (
`ip` varchar(20) NOT NULL default '',
`locatie` varchar(255) NOT NULL default '',
`tijd` varchar(30) NOT NULL default '',
`user_id` int(10) NOT NULL default '0',
`username` varchar(255) NOT NULL default ''
) TYPE=MyISAM;
Voor meer info zie code.
##
Dit script maakt gebruik van sessies
##
|
Code: |
<?
// sessie zelf instellen
if ( isSet ( $_SESSION['user_id'] ) )
{
$iUser_id = $_SESSION['user_id'];
}
else
{
$iUser_id = 0;
}
$rQueryUsernameBepalen = mysql_query ( "SELECT id, username FROM users WHERE id = ".$iUser_id ) or die ( mysql_error() );
$aQueryUsernameBepalen = mysql_fetch_assoc ( $rQueryUsernameBepalen );
$sUsername = $aQueryUsernameBepalen['username'];
/* #### INSTELBARE VARIABELEN #### */
$sIpadres = $_SERVER['REMOTE_ADDR'];
$sHuidigePagina = $_SERVER['HTTP_REFERER'];
$sTime = time()+180; // is 3 minuten
$sQuerySelectOnline = "SELECT count(*) FROM online WHERE ip = '".$_SERVER['REMOTE_ADDR']."'";
$rQuerySelectOnline = mysql_query ( $sQuerySelectOnline );
$aQuerySelectOnline = mysql_result ( $rQuerySelectOnline,0 );
// wanneer het ipadres er nog niet instaat
if ( $aQuerySelectOnline == 0 )
{
$rQueryInsert = mysql_query ( "INSERT
INTO online ( ip, locatie, tijd, user_id, username )
VALUES ('" . mysql_real_escape_string($sIpadres) . "','" . mysql_real_escape_string($sHuidigePagina) . "','" . mysql_real_escape_string($sTime) . "', '" . mysql_real_escape_string($iUser_id) . "', '" . mysql_real_escape_string($sUsername) . "' ) " ) or die ( mysql_error() );
}
else // het ipadres staat er dus wel in
{
$rQueryUpdate = mysql_query ( "UPDATE online
SET locatie='" . mysql_real_escape_string($_SERVER['HTTP_REFERER']) . "', tijd = '" . mysql_real_escape_string($sTime) . "', user_id = '" . mysql_real_escape_string($iUser_id) . "', username = '" . mysql_real_escape_string($sUsername) . "'
WHERE ip = '" . mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."'" ) or die ( mysql_error());
}
$iHuidigeTijd = time();
mysql_query("DELETE FROM online WHERE tijd < $iHuidigeTijd");
$sQueryGastenOnline = "SELECT * FROM online WHERE user_id = 0";
$rQueryGastenOnline = mysql_query ( $sQueryGastenOnline );
$iAantalGastenOnline = mysql_num_rows ( $rQueryGastenOnline );
$sQueryLedenOnline = "SELECT * FROM online WHERE user_id <> 0";
$rQueryLedenOnline = mysql_query ( $sQueryLedenOnline );
$iAantalLedenOnline = mysql_num_rows ( $rQueryLedenOnline );
echo "Gasten: ".$iAantalGastenOnline."<br />";
echo "Leden: ".$iAantalLedenOnline."<br />";
while ( $aQueryLedenOnline = mysql_fetch_assoc ( $rQueryLedenOnline ) )
{
echo '<a href=#>'.$aQueryLedenOnline['username'].'</a>,';
}
?>
<? // sessie zelf instellen if ( isSet ( $_SESSION['user_id'] ) ) { $iUser_id = $_SESSION['user_id']; } else { $iUser_id = 0; } $sUsername = $aQueryUsernameBepalen['username']; /* #### INSTELBARE VARIABELEN #### */ $sIpadres = $_SERVER['REMOTE_ADDR']; $sHuidigePagina = $_SERVER['HTTP_REFERER']; $sTime = time()+180; // is 3 minuten $sQuerySelectOnline = "SELECT count(*) FROM online WHERE ip = '".$_SERVER['REMOTE_ADDR']."'"; $rQuerySelectOnline = mysql_query ( $sQuerySelectOnline ); $aQuerySelectOnline = mysql_result ( $rQuerySelectOnline,0 ); // wanneer het ipadres er nog niet instaat if ( $aQuerySelectOnline == 0 ) { INTO online ( ip, locatie, tijd, user_id, username ) } else // het ipadres staat er dus wel in { } mysql_query("DELETE FROM online WHERE tijd < $iHuidigeTijd"); $sQueryGastenOnline = "SELECT * FROM online WHERE user_id = 0"; $rQueryGastenOnline = mysql_query ( $sQueryGastenOnline ); $sQueryLedenOnline = "SELECT * FROM online WHERE user_id <> 0"; $rQueryLedenOnline = mysql_query ( $sQueryLedenOnline ); echo "Gasten: ".$iAantalGastenOnline."<br />"; echo "Leden: ".$iAantalLedenOnline."<br />"; { echo '<a href=#>'.$aQueryLedenOnline['username'].'</a>,'; } ?>
Download code (.txt)
|
|
Stemmen |
Niet ingelogd. |
|