A
Anonymous
Guest
Pour continuer dans les scripts en AJAX, après le script d'un formulaire de contact (https://www.webrankinfo.com/forum/t/ajax-script-dun-formulaire-de-contact-de-base.64319/), je vous passe ici un script qui permet d'afficher la liste des personnes connectées (nom du membre ou visiteur, Ip Adress, localisation sur votre site et environnement client/Robot)
Un lien de test est tout en bas de mon post.
La table (qui existe déjà sur les forums IPB, sur PHPBB je ne sais pas mais il doit y avoir qqchose de similaire):
En bas de vos pages, rajouter ce code :
Sur la page whosonline.php (c'est la page ou l'on va voir la liste des connectés se recharger) :
Le fichier whosonline2.php qui va recharger la liste des connectés et l'afficher via AJAX dans la div "chargementonline" de la page whosonline2.php :
Voilà...
Le principe est de recharger via AJAX une liste de connectés toutes les X secondes sans pour autant recharger toute la charte qui va autour.
On peut aussi adapté cela à pleins d'autres cas (affichage dynamique live du nombre de connectés, ...)
Ce script est a adapté suivant votre site / forum / structure de votre base...
Je ne dis pas que mon code est parfait, d'ailleurs j'attends vos commentaires...
Cela m'a pris pas mal de temps pour extraire ce bout de code de mon site auquel il est intégré, alors il se peut que j'ai fait quelques erreurs.
Pour exemple : -http://www.compta-online.com/test-WRI.html
Pour pas faire ramer mon site, j'ai limité l'affichage a 8 connectés, rechargement toutes les 10 secondes, et j'ai bien entendu caché les IPs.
Ne restez pas tous 3 heures sur cette page sinon ca va faire planter mon site
Xp
Un lien de test est tout en bas de mon post.
La table (qui existe déjà sur les forums IPB, sur PHPBB je ne sais pas mais il doit y avoir qqchose de similaire):
Code:
CREATE TABLE `sessions` (
`id` varchar(32) NOT NULL default '',
`member_name` varchar(64) default NULL,
`member_id` mediumint(8) NOT NULL default '0',
`ip_address` varchar(16) default NULL,
`browser` varchar(255) default NULL,
`running_time` int(10) default NULL,
`login_type` tinyint(1) default NULL,
`location` varchar(40) default NULL,
`member_group` smallint(3) default NULL,
`in_forum` smallint(5) NOT NULL default '0',
`in_topic` int(10) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `in_topic` (`in_topic`),
KEY `in_forum` (`in_forum`)
) TYPE=MyISAM;
En bas de vos pages, rajouter ce code :
Code:
$session_id = md5( uniqid(microtime()) );
$IPaddr = $_SERVER["REMOTE_ADDR"];
$user_agent = $_SERVER["HTTP_USER_AGENT"];
$time_now = time();
$resultat = mysql_query("select ip_address from sessions where ip_address = '$IPaddr'");
$ligne = mysql_fetch_array($resultat, MYSQL_ASSOC);
$ip_address = $ligne["ip_address"];
$id_membre = $_COOKIE["member_id"];
// SI C'EST UN MEMBRE ON RECUPERE L'ID DANS VOTRE BASE MEMBRE
if ($id_membre != 0){
$resultat2 = mysql_query("select id,name from members where id = '$id_membre'");
$ligne = mysql_fetch_array($resultat2, MYSQL_ASSOC);
$name_membre = $ligne["name"];
$id_membre2 = $ligne["id"];
}
// SI LA SESSION EST EXPIREE, ON VIRE DE LA BASE
$session_expiration = $session_expiration ? (time() - session_expiration) : (time() - 3600);
mysql_query("DELETE FROM sessions WHERE running_time < $session_expiration");
// SI l'IP EST DEJA LOGGEE, ON MET A JOUR
if ($ip_address == $IPaddr){
mysql_query("UPDATE sessions SET location='".$page_location."',running_time='".$time_now."',in_forum='0',in_topic='0',browser='".$user_agent."' WHERE ip_address='".$IPaddr."'");
// SI L'IP EST PAS LOGGEE, ON INSERT
}else{
mysql_query("INSERT INTO sessions (id, member_name, member_id, ip_address, browser, running_time, location, login_type, member_group,in_forum,in_topic) VALUES ('".$session_id."', '".$name_membre."', '".$id_membre2."', '".$IPaddr."', '".$user_agent."', '".$time_now."', '".$page_location."', '0', '','0','0')");
}
Sur la page whosonline.php (c'est la page ou l'on va voir la liste des connectés se recharger) :
Code:
<script type="text/javascript" language="JavaScript">
var xhr = null;
var n=0;
function getXhr(){
if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}else if(window.ActiveXObject){
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}else{
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
xhr = false;
}
}
function init(){
loop();
}
function loop(){
// ICI ON SET LE LOOP : 5000 = 5 secondes
setTimeout('loop();',5000);
ShowPage();
}
function ShowPage(){
getXhr();
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
// ON DEFINI LA DIV OU ON VA CHARGER
document.getElementById('chargementonline').innerHTML=xhr.responseText;
}
}
// ICI ON SET LA PAGE QU'ON VA LOADER EN AJAX EN GET
xhr.open("GET","whosonline2.php",true);
xhr.send(null);
}
</script>
<body onLoad="init()">
<h1>Who's Online</h1>
<div id="chargementonline"> <br><br><br><center>Chargement de la liste des connectés en cours</center><br><br><br><br><br><br><br> </div>
Le fichier whosonline2.php qui va recharger la liste des connectés et l'afficher via AJAX dans la div "chargementonline" de la page whosonline2.php :
Code:
<?
// ON INTERDIT LE CACHE POUR IE, SINON IL NE RECHARGE PAS
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date du passé
include("./conf.php");
// POUR TRANSFORMER LA DATE TIMESTAMP AU BON FORMAT
function timestamp_to_date_mysql($timestamp){
return date("d/m/Y H:i", $timestamp);
}
?>
<center><table cellpadding="3" cellspacing="0">
<tr>
<td align="center" width="150">Connectés</td>
<td align="center" width="300">Lieu</td>
<td align="center" width="120">Heure</td>
<td align="center" width="190">Environnement</td>
</tr>
<?
// FONCTION POUR L'ENVIRONNEMENT OS/BROWSER
// Cette liste n'est peut être pas complétement à jour, mais il suffit de regarder qui est en ligne, et de rajouter la version du navigateur manquant ici...
$lvc_OS['Win98'] = 'Win98';
$lvc_OS['Win98'] = 'Win 9x';
$lvc_OS['Win98'] = 'Win9x';
$lvc_OS['WinNT'] = 'Win NT';
$lvc_OS['WinNT'] = 'WinNT4.0';
$lvc_OS['Win95'] = 'Win 95';
$lvc_OS['WinMe'] = 'Win Me';
$lvc_OS['WinXP'] = 'Win XP';
$lvc_OS['Win2000'] = 'Win 2000';
$lvc_OS['Linux'] = 'Linux';
$lvc_OS['Mac PPC'] = 'Mac PPC';
$lvc_OS['PPC Mac'] = 'PPC Mac';
$lvc_OS['SunOS'] = 'SunOS';
$lvc_agent['Internet Explorer'] = 'IE;';
$lvc_agent['Netscape'] = 'NS;';
$lvc_agent['Opera'] = 'OP;';
$lvc_agent['Firefox'] = 'Firefox';
$lvc_agent['Firebird'] = 'Firebird';
$lvc_agent['AppleWebKit'] = 'AppleWebKit';
$lvc_agent['Safari'] = 'Safari';
$lvc_agent['Konqueror'] = 'Konqueror';
$lvc_agent['Mozilla'] = 'Mozilla';
$lvc_other_agt['Lynx'] = 'Lynx - Linux';
$lvc_other_agt['WWWOFFLE'] = 'WWWOFFLE - Linux';
$lvc_other_agt['Konqueror'] = 'Konqueror - Linux';
$lvc_agent_versions['IE'] = Array(
'7.0',
'6.0',
'5.5',
'5.5b2',
'5.5b3',
'5.23',
'5.22',
'5.21',
'5.17',
'5.16',
'5.14',
'5.13',
'5.01',
'5.0',
'5.0b1',
'5.0b2',
'4.5',
'4.01',
'4.0',
'3.02',
'3.01'
);
$lvc_agent_versions['NS'] = Array(
'4.8',
'4.76',
'4.75',
'4.74',
'4.73',
'4.72',
'4.71',
'4.7',
'4.61',
'4.6',
'4.51',
'4.5',
'4.08',
'4.07',
'4.06',
'4.05',
'4.04',
'4.03'
);
$lvc_agent_versions['NS6'] = Array(
'8.0.1',
'7.2',
'7.1',
'7.02',
'7.01',
'7.0',
'7.1',
'6.2.3',
'6.2.2',
'6.2',
'6.1',
'6.0',
'6.1',
'm14',
'm17',
'm18'
);
$lvc_agent_versions['Firefox'] = Array(
'2.0',
'2.0b1',
'2.0b2',
'1.5.0.9',
'1.5.0.8',
'1.5.0.7',
'1.5.0.6',
'1.5.0.5',
'1.5.0.4',
'1.5.0.3',
'1.5.0.2',
'1.5.0.1',
'1.5',
'1.0.7',
'1.0.6',
'1.0.5',
'1.0.4',
'1.0.3',
'1.0.2',
'1.0.1',
'1.0',
'0.9.6',
'0.9.3',
'0.9.2',
'0.9.1',
'0.8',
'1.7.8',
'1.7.7',
'1.7.5',
'1.7.3',
'1.7.2',
'1.6',
);
$lvc_agent_versions['Firebird'] = Array(
'0.7',
);
$lvc_agent_versions['Konqueror'] = Array(
'3.2',
);
$lvc_agent_versions['Mozilla'] = Array(
'1.7.10',
'rv:1.7.10',
'rv:1.7.8',
'1.7.8',
'1.7.3',
'1.7',
'1.4',
);
$lvc_agent_versions['AppleWebKit'] = Array(
'1.7.5',
'1.7.3',
'1.6',
'1.0.2',
);
$lvc_agent_versions['Safari'] = Array(
'419.3',
'417.9.3',
'417.9.2',
'85.5',
'85.6',
'85.8',
'85.8.1',
'417.8',
'416.12',
'412',
'312',
'125.12',
'125.1',
'125.9',
'125.8',
);
$lvc_agent_versions['Camino'] = Array(
'0.8.4',
'0.8.3',
'0.8.2',
'0.8.1',
'0.8int',
);
$lvc_agent_versions['OP'] = Array(
'9.00',
'8.5',
'8.0',
'7.53',
'7.5',
'7.0',
'5.12',
'5.11',
'5.0',
'4.0',
'3.60',
'3.62'
);
$lvc_agent_os['IE'] = Array(
'Windows 95' => 'Win95',
'Win32' => 'Win95',
'Win 9x 4.90' => 'WinMe',
'Windows 98' => 'Win98',
'Windows NT 5.0' => 'Win2000',
'Windows NT 5.1' => 'WinXP',
'Windows NT' => 'WinNT',
'Mac PowerPC' => 'Mac PPC',
'Mac PPC' => 'Mac PPC',
'SunOS' => 'SunOS',
);
$lvc_agent_os['NS'] = Array(
'Win95' => 'Win95',
'Win 9x 4.90' => 'WinMe',
'Win98' => 'Win98',
'WinNT' => 'WinNT',
'Windows NT 5.0' => 'Win2000',
'Windows NT 5.1' => 'WinXP',
'Windows NT' => 'WinNT',
'Linux' => 'Linux',
'SunOS' => 'SunOS',
'PPC' => 'Mac PPC',
'FreeBSD' => 'FreeBSD',
'AIX' => 'AIX',
'IRIX' => 'IRIX',
'HP-UX' => 'HP-UX',
'OS/2' => 'OS/2',
'NetBSD' => 'NetBSD'
);
$lvc_agent_os['NS6'] = Array(
'Win95' => 'Win95',
'Win 9x 4.90' => 'WinMe',
'Win98' => 'Win98',
'WinNT' => 'WinNT',
'Windows NT 5.0' => 'Win2000',
'Windows NT 5.1' => 'WinXP',
'Windows NT' => 'WinNT',
'Linux' => 'Linux',
'SunOS' => 'SunOS',
'PPC' => 'Mac PPC',
'FreeBSD' => 'FreeBSD',
'AIX' => 'AIX',
'IRIX' => 'IRIX',
'HP-UX' => 'HP-UX',
'OS/2' => 'OS/2',
'NetBSD' => 'NetBSD'
);
$lvc_agent_os['OP'] = Array(
'Windows 95' => 'Win95',
'Windows 98' => 'Win98',
'Windows 2000' => 'Win2000',
'Win 9x 4.90' => 'WinMe',
'Windows NT 5.0' => 'Win2000',
'Windows NT 5.1' => 'WinXP',
'Windows NT' => 'WinNT',
'Linux' => 'Linux'
);
$lvc_agent_os['Firefox'] = Array(
'Windows 95' => 'Win95',
'Windows 98' => 'Win98',
'Win98' => 'Win98',
'Windows 2000' => 'Win2000',
'Win 9x 4.90' => 'WinMe',
'Windows NT 5.0' => 'Win2000',
'Windows NT 5.1' => 'WinXP',
'Windows NT' => 'WinNT',
'WinNT4.0' => 'WinNT',
'Linux' => 'Linux',
'Mac OS X' => 'Mac OS X',
'FreeBSD' => 'FreeBSD',
'SunOS' => 'SunOS',
);
$lvc_agent_os['Mozilla'] = Array(
'Windows 95' => 'Win95',
'Windows 98' => 'Win98',
'Win98' => 'Win98',
'Windows 2000' => 'Win2000',
'Win 9x 4.90' => 'WinMe',
'Windows NT 5.0' => 'Win2000',
'Windows NT 5.1' => 'WinXP',
'Windows NT' => 'WinNT',
'Linux' => 'Linux',
'Mac OS X' => 'Mac OS X',
'FreeBSD' => 'FreeBSD',
'SunOS' => 'SunOS',
);
$lvc_agent_os['Firebird'] = Array(
'Windows 95' => 'Win95',
'Windows 98' => 'Win98',
'Windows 2000' => 'Win2000',
'Win 9x 4.90' => 'WinMe',
'Windows NT 5.0' => 'Win2000',
'Windows NT 5.1' => 'WinXP',
'Windows NT' => 'WinNT',
'Linux' => 'Linux',
'Mac OS X' => 'Mac OS X',
'SunOS' => 'SunOS',
);
$lvc_agent_os['Safari'] = Array(
'Mac OS X' => 'Mac OS X',
);
$lvc_agent_os['Konqueror'] = Array(
'Linux' => 'Linux',
);
$lvc_agent_os['Camino'] = Array(
'Mac OS X' => 'Mac OS X',
'PPC Mac OS X Mach-O' => 'Mac OS X',
);
//Mozilla/5.0 (compatible; Konqueror/3.2; Linux) KHTML/3.2.3 (like Gecko)
//Mozilla/5.0 (compatible; Konqueror/3.2; Linux) (KHTML, like Gecko)
//Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007 Firebird/0.7
//Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax)
//Mozilla/4.0 (compatible; grub-client-2.6.0)
//Mozilla/5.0 (Windows; U; Win98; fr-FR; rv:1.7.10)
//psbot/0.1 ( http://www.picsearch.com/bot.html)
//InsurancoBot( http://www.insuranco.de/bot.html)
// ------------------------------------------------------------------------- //
function analyse_agent($agt){
$lvc_agent_max_length = "300";
global $lvc_agent_max_length;
global $lvc_agent_versions;
global $lvc_agent_versions_2;
global $lvc_agent_os;
global $lvc_other_agt;
$agt = strtr($agt, '+', ' ');
if (ereg('MSIE', $agt) && !ereg('Opera', $agt)){ // Internet Explorer
$new_agt = 'IE';
$agt = strtr($agt, '_', ' ');
for ($cnt = 0, $ok = false;
$cnt < sizeof($lvc_agent_versions['IE']) && !$ok;
$cnt++){
if ($ok = ereg($lvc_agent_versions['IE'][$cnt], $agt)){
$new_agt .= ';'.$lvc_agent_versions['IE'][$cnt];
for (@reset($lvc_agent_os['IE']), $ok = false;
(list($key, $value) = @each($lvc_agent_os['IE'])) && !$ok;){
if ($ok = ereg($key, $agt))
$new_agt .= ';'.$value;
}
}
}
if (!$ok) $new_agt = $agt;
}elseif (ereg('Opera', $agt)){ // Opera
$new_agt = 'OP';
for ($cnt = 0, $ok = false;
$cnt < sizeof($lvc_agent_versions['OP']) && !$ok;
$cnt++){
if ($ok = ereg($lvc_agent_versions['OP'][$cnt], $agt)){
$new_agt .= ';'.$lvc_agent_versions['OP'][$cnt];
for (@reset($lvc_agent_os['OP']), $ok = false;
(list($key, $value) = @each($lvc_agent_os['OP'])) && !$ok;){
if ($ok = ereg($key, $agt))
$new_agt .= ';'.$value;
}
}
}
if (!$ok) $new_agt = $agt;
}elseif (ereg('Mozilla/4.', $agt)){ // Netscape 4.x
$new_agt = 'NS';
for ($cnt = 0, $ok = false;
$cnt < sizeof($lvc_agent_versions['NS']) && !$ok;
$cnt++){
if ($ok = ereg($lvc_agent_versions['NS'][$cnt], $agt)){
$new_agt .= ';'.$lvc_agent_versions['NS'][$cnt];
for (@reset($lvc_agent_os['NS']), $ok = false;
(list($key, $value) = @each($lvc_agent_os['NS'])) && !$ok;){
if ($ok = ereg($key, $agt))
$new_agt .= ';'.$value;
}
}
}
if (!$ok) $new_agt = $agt;
}elseif (ereg('Safari', $agt)){ // Safari
$new_agt = 'Safari';
for ($cnt = 0, $ok = false;
$cnt < sizeof($lvc_agent_versions['Safari']) && !$ok;
$cnt++){
if ($ok = ereg($lvc_agent_versions['Safari'][$cnt], $agt)){
$new_agt .= ';'.$lvc_agent_versions['Safari'][$cnt];
for (@reset($lvc_agent_os['Safari']), $ok = false;
(list($key, $value) = @each($lvc_agent_os['Safari'])) && !$ok;){
if ($ok = ereg($key, $agt))
$new_agt .= ';'.$value;
}
}
}
if (!$ok) $new_agt = $agt;
}elseif (ereg('Firefox', $agt)){ // Firefox
$new_agt = 'Firefox';
for ($cnt = 0, $ok = false;
$cnt < sizeof($lvc_agent_versions['Firefox']) && !$ok;
$cnt++){
if ($ok = ereg($lvc_agent_versions['Firefox'][$cnt], $agt)){
$new_agt .= ';'.$lvc_agent_versions['Firefox'][$cnt];
for (@reset($lvc_agent_os['Firefox']), $ok = false;
(list($key, $value) = @each($lvc_agent_os['Firefox'])) && !$ok;){
if ($ok = ereg($key, $agt))
$new_agt .= ';'.$value;
}
}
}
if (!$ok) $new_agt = $agt;
}elseif (ereg('Netscape', $agt) && !ereg('Konqueror', $agt)){ // NS 6
$new_agt = 'NS';
for ($cnt = 0, $ok = false;
$cnt < sizeof($lvc_agent_versions['NS6']) && !$ok;
$cnt++){
if ($ok = ereg($lvc_agent_versions['NS6'][$cnt], $agt)){
$new_agt .= ';'.$lvc_agent_versions['NS6'][$cnt];
for (@reset($lvc_agent_os['NS']), $ok = false;
(list($key, $value) = @each($lvc_agent_os['NS'])) && !$ok;){
if ($ok = ereg($key, $agt))
$new_agt .= ';'.$value;
}
}
}
if (!$ok) $new_agt = $agt;
}elseif (ereg('Gecko', $agt)){ // MOZILLA
$new_agt = 'Mozilla';
for ($cnt = 0, $ok = false;
$cnt < sizeof($lvc_agent_versions['Mozilla']) && !$ok;
$cnt++){
if ($ok = ereg($lvc_agent_versions['Mozilla'][$cnt], $agt)){
$new_agt .= ';'.$lvc_agent_versions['Mozilla'][$cnt];
for (@reset($lvc_agent_os['Mozilla']), $ok = false;
(list($key, $value) = @each($lvc_agent_os['Mozilla'])) && !$ok;){
if ($ok = ereg($key, $agt))
$new_agt .= ';'.$value;
}
}
}
if (!$ok) $new_agt = $agt;
}
else // others
{
$new_agt = $agt;
for (@reset($lvc_other_agt), $ok = false;
(list($key, $value) = @each($lvc_other_agt)) && !$ok;){
if ($ok = ereg($key, $agt))
$new_agt = $value;
}
}
$new_agt = strip_tags($new_agt);
if (strlen($new_agt) > 200)
$new_agt = substr($new_agt, 0, $lvc_agent_max_length-4).' ...';
return($new_agt);
}
$a = 0;
// ON RECUPERE DANS LA BASE LES 30 DERNIERS CONNECTES
$resultat = mysql_query("SELECT * FROM sessions ORDER BY running_time DESC LIMIT 0,30");
while($ligne = mysql_fetch_array($resultat)){
//DATE
$running_time = timestamp_to_date_mysql($ligne["running_time"]);
//MEMBRE OU VISITEUR
$member_name = $ligne["member_name"];
$member_name = strtolower($member_name);
$member_name = ucfirst($member_name);
$member_id = $ligne["member_id"];
//IP
$ip_address = $ligne["ip_address"];
//LOCATION
$location = $ligne["location"];
$in_forum = $ligne["in_forum"];
$in_topic = $ligne["in_topic"];
// NAVIGATEUR + OS OU ROBOT
$browser = $ligne["browser"];
$browser = analyse_agent($browser);
// ATTENTION CETTE LISTE N'EST SUREMENT PAS A JOUR
// Idem que pour la lite des navigateur, il suffit de regarder la liste de connectés pour mettre a jour la liste de ROBOTS
switch($browser){
case "Mozilla/5.0 (compatible; Googlebot/2.1; https://www.google.com/bot.html)": $browser="<font class=\"blue\">Robot Google 2.1</font>"; break;
case "Mozilla/5.0 (compatible; Googlebot/2.1; +https://www.google.com/bot.html)": $browser="<font class=\"blue\">Robot Google 2.1</font>"; break;
case "Googlebot/2.1 (+https://www.google.com/bot.html)": $browser="<font class=\"blue\">Robot Google 2.1</font>"; break;
case "Googlebot/2.1 ( https://www.google.com/bot.html)": $browser="<font class=\"blue\">Robot Google 2.1</font>"; break;
case "Googlebot/2.1 (https://www.google.com/bot.html)": $browser="<font class=\"blue\">Robot Google 2.1</font>"; break;
case "Mediapartners-Google/2.1": $browser="<font class=\"blue\">Mediapartners</font>"; break;
case strpos($browser,"Teoma"): $browser="<font class=\"blue\">Teoma Robot</font>"; break;
case "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; http://sp.ask.com/docs/about/tech_crawling.html)": $browser="<font class=\"blue\">Teoma Robot</font>"; break;
case "Mozilla/4.0 compatible ZyBorg/1.0 (wn-12.zyborg@looksmart.net; http://www.WISEnutbot.com)": $browser="<font class=\"blue\">Robot Looksmart v1.0</font>"; break;
case "Mozilla/4.0 compatible ZyBorg/1.0 (wn-14.zyborg@looksmart.net; http://www.WISEnutbot.com)": $browser="<font class=\"blue\">Robot Looksmart v1.0</font>"; break;
case "Mozilla/4.0 compatible ZyBorg/1.0 Dead Link Checker (wn.dlc@looksmart.net; http://www.WISEnutbot.com)": $browser="<font class=\"blue\">Robot Looksmart v1.0</font>"; break;
case "Mozilla/4.0 (compatible; grub-client-2.6.1)": $browser="<font class=\"blue\">Robot Looksmart</font>"; break;
case "Mozilla/4.0 (compatible; grub-client-2.6.0)": $browser="<font class=\"blue\">Robot Looksmart</font>"; break;
case "Mozilla/4.0 (compatible; Cerberian Drtrs Version-3.2-Build-0)": $browser="<font class=\"blue\">Robot Cerberian</font>"; break;
case "Mozilla/5.0 (compatible; BecomeBot/2.0.3; http://www.become.com/webmasters.html)": $browser="<font class=\"blue\">Become Robot 2.0.3</font>"; break;
case "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)": $browser="<font class=\"blue\">Robot Yahoo</font>"; break;
case "Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)": $browser="<font class=\"blue\">Robot Yahoo China</font>"; break;
case "Mozilla/5.0 (compatible; BecomeBot/3.0; MSIE 6.0 compatible; http://www.become.com/site owners.html)": $browser="<font class=\"blue\">BecomeBot 3.0</font>"; break;
case "TurnitinBot/2.0 http://www.turnitin.com/robot/crawlerinfo.html": $browser="<font class=\"blue\">Robot Turnitin 2.0</font>"; break;
case "ia_archiver": $browser="<font class=\"blue\">Alexa Robot (ia_archiver)</font>"; break;
case "appie 1.1 (www.walhello.com)": $browser="<font class=\"blue\">Robot Walhello </font>"; break;
case "ConveraCrawler/0.4": $browser="<font class=\"blue\">Robot Convera 0.4</font>"; break;
case "ConveraCrawler/0.8 ( http://www.authoritativeweb.com/crawl)": $browser="<font class=\"blue\">Robot Convera 0.8</font>"; break;
case "ConveraCrawler/0.9d ( http://www.authoritativeweb.com/crawl)": $browser="<font class=\"blue\">Robot Convera 0.9</font>"; break;
case "Iltrovatore-Setaccio/1.2 (It-bot; http://www.iltrovatore.it/bot.html; info@iltrovatore.it)": $browser="<font class=\"blue\">Iltrovatore Robot Italien</font>"; break;
case "Seekbot/1.0 (http://www.seekbot.net/bot.html) HTTPFetcher/0.3": $browser="<font class=\"blue\">SEEKBOT Robot 3.0</font>"; break;
case "NutchCVS/0.06-dev (Nutch; http://www.nutch.org/docs/en/bot.html; nutch-agent@lists.sourceforge.net)": $browser="<font class=\"blue\">Robot Looksmart</font>"; break;
case "NutchCVS/0.05 (Nutch; http://www.nutch.org/docs/en/bot.html; nutch-agent@lists.sourceforge.net)": $browser="<font class=\"blue\">Robot Looksmart</font>"; break;
case "sherlock/1.0": $browser="<font class=\"blue\">Robot Sherlock v1.0</font>"; break;
case "Wotbox/0.7-alpha (bot@wotbox.com; http://www.wotbox.com)": $browser="<font class=\"blue\">Robot Wotbox/0.7-alpha</font>"; break;
case "http://www.almaden.ibm.com/cs/crawler [bc23]": $browser="<font class=\"blue\">Robot Almaden bc23</font>"; break;
case "IRLbot/1.0 ( http://irl.cs.tamu.edu/crawler)": $browser="<font class=\"blue\">Robot IRLbot v1.0</font>"; break;
case "msnbot/0.3 (+http://search.msn.com/msnbot.htm)": $browser="<font class=\"blue\">Robot MSN 0.3</font>"; break;
case "msnbot/0.9 ( http://search.msn.com/msnbot.htm)": $browser="<font class=\"blue\">Robot MSN 0.9</font>"; break;
case "msnbot/1.0 (+http://search.msn.com/msnbot.htm)": $browser="<font class=\"blue\">Robot MSN 1.0</font>"; break;
case "msnbot/1.0 ( http://search.msn.com/msnbot.htm)": $browser="<font class=\"blue\">Robot MSN 1.0</font>"; break;
case "aipbot/1.0 (aipbot; http://www.aipbot.com; aipbot@aipbot.com)": $browser="<font class=\"blue\">Aipbot</font>"; break;
case "Gigabot/2.0": $browser="<font class=\"blue\">Robot Gigabot</font>"; break;
case "psbot/0.1 ( http://www.picsearch.com/bot.html)": $browser="<font class=\"blue\">Robot Picsearch</font>"; break;
case "InsurancoBot( http://www.insuranco.de/bot.html)": $browser="<font class=\"blue\">InsurancoBot</font>"; break;
case "IP*Works! V5 HTTP/S Component - by /n software - www.nsoftware.com": $browser="<font class=\"red\">IP protégée</font>"; break;
case "FAST MetaWeb Crawler (helpdesk at fastsearch dot com)": $browser="<font class=\"blue\">FastSearch Bot</font>"; break;
case "e-SocietyRobot(http://www.yama.info.waseda.ac.jp/~yamana/es/)": $browser="<font class=\"blue\">e-SocietyRobot</font>"; break;
case "Baiduspider (http://www.baidu.com/search/spider.htm)": $browser="<font class=\"blue\">Baiduspider</font>"; break;
case "Baiduspider ( http://www.baidu.com/search/spider.htm)": $browser="<font class=\"blue\">Baiduspider</font>"; break;
case "Gigabot/2.0/gigablast.com/spider.html": $browser="<font class=\"blue\">Gigabot</font>"; break;
case "BIGLOTRON (Beta 2;GNU/Linux)": $browser="<font class=\"blue\">Robot Biglotron</font>"; break;
case "SBIder/0.8-dev (SBIder; http://www.sitesell.com/sbider.html; http://support.sitesell.com/contact-support.html)": $browser="<font class=\"blue\">Robot SBIder 0.8</font>"; break;
}
// ON AFFICHE LES RESULTATS EN 2 LIGNES DE COULEURS DIFFERENTES
// A VOUS DE DEFINIR DANS VOTRE CSS : la class "row1" et ""row2"
if($a % 2 ==0){
echo "<tr>
<td class=\"row1\" align=\"left\" width=\"150\">";
if ($member_name == ""){
echo "Visiteur";
}else{ // ON AFFICHE LE NOM DU MEMBRE AVEC UN LIEN VERS SA FICHE
echo "<a href=\"".$url."forum/index.php?showuser=".$member_id."\"><strong>".$member_name."</strong></a>";
}
echo " (".$ip_address.")</td>
<td class=\"row1\" align=\"left\" width=\"300\">".$location."</td>
<td class=\"row1\" align=\"center\" width=\"120\">".$running_time."</td>
<td class=\"row1\" align=\"center\" width=\"190\">".$browser."</td>
</tr>
<tr><td colspan=\"5\" height=\"2\"><img src=\"blank.gif\" height=\"2\"></td></tr>";
}else{
echo "<tr>
<td class=\"row2\" align=\"left\" width=\"150\">";
if ($member_name == ""){
echo "Visiteur";
}else{
echo "<a href=\"".$url."forum/index.php?showuser=".$member_id."\"><strong>".$member_name."</strong></a>";
}
echo " (".$ip_address.")</td>
<td class=\"row2\" align=\"left\" width=\"300\">".$location."</td>
<td class=\"row2\" align=\"center\" width=\"120\">".$running_time."</td>
<td class=\"row2\" align=\"center\" width=\"190\">".$browser."</td>
</tr>
<tr><td colspan=\"5\" height=\"2\"><img src=\"blank.gif\" height=\"2\"></td></tr>";
}
$a++;
}
?>
</table></center>
Voilà...
Le principe est de recharger via AJAX une liste de connectés toutes les X secondes sans pour autant recharger toute la charte qui va autour.
On peut aussi adapté cela à pleins d'autres cas (affichage dynamique live du nombre de connectés, ...)
Ce script est a adapté suivant votre site / forum / structure de votre base...
Je ne dis pas que mon code est parfait, d'ailleurs j'attends vos commentaires...
Cela m'a pris pas mal de temps pour extraire ce bout de code de mon site auquel il est intégré, alors il se peut que j'ai fait quelques erreurs.
Pour exemple : -http://www.compta-online.com/test-WRI.html
Pour pas faire ramer mon site, j'ai limité l'affichage a 8 connectés, rechargement toutes les 10 secondes, et j'ai bien entendu caché les IPs.
Ne restez pas tous 3 heures sur cette page sinon ca va faire planter mon site
Xp