Annonceindlæg fra Kingston Technology
01. september 2003 - 13:08
#5
Her er en kode som jeg en gang fik lavet : Gem denne kode i en fil og include filen på alle dise sider. <? $online_time = mktime(); $timenow = mktime(); $timedel = mktime()-160; $side = "$_SERVER[REQUEST_URI]"; con_db(); mysql_query("DELETE FROM online WHERE tid<'$timedel'"); $query = mysql_query("SELECT user FROM online WHERE ip='$REMOTE_ADDR'"); @$user = mysql_result($query, 0, "user"); $antal = mysql_num_rows($query); if ($antal > 0) { if ($_SESSION[brugernavn]) { if ($user == "Gæst") mysql_query("UPDATE online SET side ='$side', tid='$timenow', user='$_SESSION[brugernavn]' WHERE ip='$REMOTE_ADDR'"); else if ($user == $_SESSION[brugernavn]) mysql_query("UPDATE online SET side ='$side', tid='$timenow' WHERE ip='$REMOTE_ADDR'"); else mysql_query("INSERT INTO online (user, tid, ip, side, online_time) VALUES ('$_SESSION[brugernavn]', '$timenow', '$REMOTE_ADDR','$side','$online_time')"); } else { mysql_query("UPDATE online SET tid='$timenow', user='Gæst' side ='$side',online_time ='$online_time' WHERE ip='$REMOTE_ADDR'"); } } else { if ($_SESSION[brugernavn]) mysql_query("INSERT INTO online (user, tid, ip, side, online_time) VALUES ('$_SESSION[brugernavn]', '$timenow', '$REMOTE_ADDR','$side','$online_time')"); else mysql_query("INSERT INTO online (user, tid, ip, side, online_time) VALUES ('Gæst', '$timenow', '$REMOTE_ADDR','$side','$online_time')"); } ?> Der efter kan du bare hive data ud af MySQL. Og her er selve koden til at lave en online side :) <br> <table border="0" width="100%" cellspacing="0" cellpadding="0" class="ramme_bund"> <tr> <td width="100%"><span class='header'>Brugere online</span></td> </tr> </table> <br style='font-size: 10px;'> <table border="0" width="100%" cellpadding="4" cellspacing="0" class='tabel'> <tr> <td width="33%"><span class='m'><b>Brugernavn</b></span></td> <td width="16%"> <p align="center"><span class='m'><b>Status</b></span></td> <td width="25%"> <p align="center"><span class='m'><b>Befinder sig på</b></span></td> <td width="25%"> <p align="center"><span class='m'><b>Online tid</b></span></td> </tr> </table> <br style='font-size: 3px;'> <? echo" <table border='0' width='100%' cellpadding='4' cellspacing='0' class='tabel'> <tr> <td width='100%'>"; con_db(); $result = mysql_query("SELECT * FROM online ORDER BY tid DESC") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $user = ucfirst($row[user]); $online_time = $row[online_time]; if ($user == "Gæst") { $visside2 = preg_replace("/^\//i", "", $row[side]) ; echo" <table border='0' width='100%' cellpadding='4' cellspacing='0' lass='tabel_bund_stip'> <tr> <td width='34%'><span class='m'>$row[user]</span> </td> <td width='16%'> <p align='center'><span class='m'>Besøgende</span></td> <td width='25%'> <p align='center'><span class='m'><a href='$row[side]' target='_blanc'>$visside2</a></span></td> <td width='25%'> <p align='center'><span class='m'>"; $mkt = mktime(); $since_t = $online_time - $mkt; $s_min = str_replace("-", "", $since_t / 60); $s_tim = round(str_replace("-", "", $since_t / 3600)); $s_dag = round(str_replace("-", "", $since_t / 84600)); if((substr($s_tim, 0, 1) == 0) && (substr($s_dag, 0, 1) == 0)) { echo "".number_format($s_min, 0, '', '')." min."; } if((substr($s_tim, 0, 1) > 0) && (substr($s_dag, 0, 1) == 0)) { echo "".round($s_tim)." time(r)"; } if(round($s_dag) > 0) { echo "".round($s_dag)." dag(e)"; }echo"</span></td> </tr> </table>"; } else{ $query = mysql_query("SELECT * FROM brugere WHERE brugernavn='$row[user]'"); $row1 = mysql_fetch_array($query); $user = ucfirst($row[user]); $online_time = $row[online_time]; echo " <table border='0' width='100%' cellpadding='4' cellspacing='0' class='tabel_bund_stip'> <tr> <td width='34%'><span class='m'><a href='profil.php?bruger=$row1[brugernavn]'>$row1[brugernavn]</a></span>"; if($row1[foto]=="kommersnart.gif"){ echo "<span class='s'><font color='#DDDDDD'><i> [foto]</i></font></span>"; } else { echo " <span class='s'><a href='vis_profil_foto.php?foto=$row1[foto]' target='_blanc' t>[foto]</a></span>"; } echo" </td> <td width='16%'> <p align='center'><span class='m'>$row1[status]</span></td> <td width='25%'> <p align='center'><span class='m'>"; $visside = preg_replace("/^\//i", "", $row[side]) ; echo" <a href='$row[side]' target='_blanc'>$visside</a></span></td> <td width='25%'> <p align='center'><span class='m'>"; $mkt = mktime(); $since_t = $online_time - $mkt; $s_min = str_replace("-", "", $since_t / 60); $s_tim = round(str_replace("-", "", $since_t / 3600)); $s_dag = round(str_replace("-", "", $since_t / 84600)); if((substr($s_tim, 0, 1) == 0) && (substr($s_dag, 0, 1) == 0)) { echo "".number_format($s_min, 0, '', '')." min."; } if((substr($s_tim, 0, 1) > 0) && (substr($s_dag, 0, 1) == 0)) { echo "".round($s_tim)." time(r)"; } if(round($s_dag) > 0) { echo "".round($s_dag)." dag(e)"; }echo"</span></td> </tr> </table>"; } } ?> </td> </tr> </table> Alle det steder hvor der står con_db(); skal du lave en MySQL connection Her er så MySQL dump : # # Struktur dump for tabellen `online` # CREATE TABLE online ( id int(32) NOT NULL auto_increment, tid varchar(15) NOT NULL default '', user varchar(15) NOT NULL default '', side varchar(255) NOT NULL default '/index.php', ip varchar(20) NOT NULL default '', online_time varchar(15) NOT NULL default '', PRIMARY KEY (id) ) TYPE=MyISAM;