Accueil > > > FICHIER D'HISTORIQUE DES CONNEXIONS (LOG) À UNE PAGE (SANS MYSQL)
FICHIER D'HISTORIQUE DES CONNEXIONS (LOG) À UNE PAGE (SANS MYSQL)
Information sur la source
Description
A chaque chargement du script, une ligne est ajoutée au fichier d'historique présenté sous forme d'une liste à plusieurs colonnes : action, jour, heure, login, ip, os et navigateur. pour mes besoins j'ai 3 types d'enregistrements : connexion, ouverture de compte et fermeture de compte. L'intérêt principal de ceci est de ne pas utiliser de base de données (cela est util pour certains), mais le script est donc forcément de plus en plus lent au fur et a mesure du nombre de visites (mais rien de rédibitoire, rassurez vous!) Donc si vous utilisez une base (mysql...), préférez un accès base qu'une modification comme celle ci d'un fichier texte :)
Source
- Page "log.html" :
- ________________________________________________________________
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head><title>Fichier Log</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <link href="style.css" rel="stylesheet" type="text/css" />
- <div align="center"><h1>Fichier Log</h1></div>
- <table width="80%" border="0" cellspacing="2" cellpadding="0" align="center"><thead>
- Légende : <span style="font-face: Courier New, Lucida Console; font-weight: bold;">=></span> Logged in <span style="font-face: Courier New, Lucida Console; font-weight: bold; background-color: #44DD44;">++</span> Subscribed <span style="font-face: Courier New, Lucida Console; font-weight: bold; background-color: #DD5555;">--</span> Unsubscribed
- <br><br></thead>
- <tr><th>Action</th><th>Jour</th><th>Heure</th><th>Login</th><th>Adresse IP</th><th>Système d'exploitation</th><th>Navigateur</th></tr>
- <tr><td style="font-face: Courier New, Lucida Console; font-weight: bold;" align="center">=></td><td>11/05/2004</td><td>20:03</td><td>mout</td><td>192.168.0.22</td><td>Windows XP</td><td>Internet Explorer</td></tr>
- ________________________________________________________________
-
-
- script à intégrer dans une page d'autentification par exemple :
- ________________________________________________________________
- <?php
- //detection des parametres de l'utilisateur :
- $agent = $_SERVER['HTTP_USER_AGENT'];
- /* navigateur : */
- if ($agent == "") { }
- elseif (eregi("MSIE", $agent)) { $nav="Internet Explorer"; }
- elseif (eregi("Mozilla", $agent)) { $nav = "Netscape"; }
- else { $nav = "Autres"; }
- if ($agent == "") { }
-
- /* WINDOWS */
- elseif (eregi("Windows", $agent))
- {
- if(eregi("95", $agent)) { $os = 'Windows 95'; }
- elseif (eregi("98; Win 9x", $agent)) { $os = 'Windows Me'; }
- elseif (eregi("98", $agent)) { $os = 'Windows 98'; }
- elseif (eregi("NT 5.0", $agent)) { $os = 'Windows 2000'; }
- elseif (eregi("NT 5.1", $agent)) { $os = 'Windows XP'; }
- elseif (eregi("NT", $agent)) { $os = 'Windows NT'; }
- else { $os = 'Autres Windows'; }
- }
-
- /* LINUX */
- elseif (eregi("linux", $agent)) { $os = 'Linux'; }
-
- /* BEOS */
- elseif (eregi("beos", $agent)) { $os = 'BeOS'; }
-
- /* AUTRE */
- else { $os = 'Autres'; }
-
- $ip=$_SERVER["REMOTE_ADDR"];
-
- /*------------------------------------------*/
-
- $filename = "log.html";
- $file = fopen($filename, "r");
- $log_avant = fread($file, filesize($filename));
- fclose($file);
- $file = fopen($filename, "w");
- $color = "#FFFFFF"; //couleur d'arriere plan de la ligne en cours (est changé chez moi selon le type de connexion (simple, inscription ou desinscription)
- $log_apres = $log_avant."<tr style=\"background-color: $color;\"><td style=\"font-face: Courier New, Lucida Console; font-weight: bold;\" align=\"center\">=></td><td>".date("d/m/Y")."</td><td>".date("H:i")."</td><td>$login</td><td>$ip</td><td>$os</td><td>$nav</td></tr>\r\n";
- fwrite($file, $log_apres);
- fclose($file);
- ?>
Page "log.html" :
________________________________________________________________
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Fichier Log</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css" />
<div align="center"><h1>Fichier Log</h1></div>
<table width="80%" border="0" cellspacing="2" cellpadding="0" align="center"><thead>
Légende : <span style="font-face: Courier New, Lucida Console; font-weight: bold;">=></span> Logged in <span style="font-face: Courier New, Lucida Console; font-weight: bold; background-color: #44DD44;">++</span> Subscribed <span style="font-face: Courier New, Lucida Console; font-weight: bold; background-color: #DD5555;">--</span> Unsubscribed
<br><br></thead>
<tr><th>Action</th><th>Jour</th><th>Heure</th><th>Login</th><th>Adresse IP</th><th>Système d'exploitation</th><th>Navigateur</th></tr>
<tr><td style="font-face: Courier New, Lucida Console; font-weight: bold;" align="center">=></td><td>11/05/2004</td><td>20:03</td><td>mout</td><td>192.168.0.22</td><td>Windows XP</td><td>Internet Explorer</td></tr>
________________________________________________________________
script à intégrer dans une page d'autentification par exemple :
________________________________________________________________
<?php
//detection des parametres de l'utilisateur :
$agent = $_SERVER['HTTP_USER_AGENT'];
/* navigateur : */
if ($agent == "") { }
elseif (eregi("MSIE", $agent)) { $nav="Internet Explorer"; }
elseif (eregi("Mozilla", $agent)) { $nav = "Netscape"; }
else { $nav = "Autres"; }
if ($agent == "") { }
/* WINDOWS */
elseif (eregi("Windows", $agent))
{
if(eregi("95", $agent)) { $os = 'Windows 95'; }
elseif (eregi("98; Win 9x", $agent)) { $os = 'Windows Me'; }
elseif (eregi("98", $agent)) { $os = 'Windows 98'; }
elseif (eregi("NT 5.0", $agent)) { $os = 'Windows 2000'; }
elseif (eregi("NT 5.1", $agent)) { $os = 'Windows XP'; }
elseif (eregi("NT", $agent)) { $os = 'Windows NT'; }
else { $os = 'Autres Windows'; }
}
/* LINUX */
elseif (eregi("linux", $agent)) { $os = 'Linux'; }
/* BEOS */
elseif (eregi("beos", $agent)) { $os = 'BeOS'; }
/* AUTRE */
else { $os = 'Autres'; }
$ip=$_SERVER["REMOTE_ADDR"];
/*------------------------------------------*/
$filename = "log.html";
$file = fopen($filename, "r");
$log_avant = fread($file, filesize($filename));
fclose($file);
$file = fopen($filename, "w");
$color = "#FFFFFF"; //couleur d'arriere plan de la ligne en cours (est changé chez moi selon le type de connexion (simple, inscription ou desinscription)
$log_apres = $log_avant."<tr style=\"background-color: $color;\"><td style=\"font-face: Courier New, Lucida Console; font-weight: bold;\" align=\"center\">=></td><td>".date("d/m/Y")."</td><td>".date("H:i")."</td><td>$login</td><td>$ip</td><td>$os</td><td>$nav</td></tr>\r\n";
fwrite($file, $log_apres);
fclose($file);
?>
Conclusion
La fin de la page html est volontairement laissée ouverte (pas de </body></html> ni de footer) car on y rajoute directement les lignes...
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
INTéGRATION YAMMER ET SHAREPOINT ONLINE (OFFICE 365), éTAPE 1 .INTéGRATION YAMMER ET SHAREPOINT ONLINE (OFFICE 365), éTAPE 1 . par Patrick Guimonet
#Yammer Certains s'en sont déjà fait l'écho (ici en allemand par exemple : Yammer Integration in Office 365 Phase 1) ou bien sûr sur le blog SharePoint : Make Yammer your default social network in Office 365 en anglais. Mais c'e...
Cliquez pour lire la suite de l'article par Patrick Guimonet [DYNAMICS CRM] AJOUTER LES DOSSIERS DE CRM AU DOSSIER FAVORIS D'OUTLOOK[DYNAMICS CRM] AJOUTER LES DOSSIERS DE CRM AU DOSSIER FAVORIS D'OUTLOOK par bianca
Objectif
Pour aller plus rapidement dans les menus de Dynamics CRM depuis votre client CRM pour Outlook, vous pouvez utiliser le dossier des Favoris d'Outlook. En effet, par simple glisser/déplacer, vous pouvez déposer un éléme...
Cliquez pour lire la suite de l'article par bianca VISUAL STUDIO 2013VISUAL STUDIO 2013 par Etienne Margraff
Ahh, ENFIN ! c'est officiel, il va y avoir un VS et un TFS 2013. De nouvelles fonctionnalités qui vont à mon sens assoir la maturité de TFS qui est maintenant l'outil incontournable pour tout projet (.NET, mais pas seulement !). Si vous n'avez pas jet...
Cliquez pour lire la suite de l'article par Etienne Margraff CONFIGURER LA COLLATION SQL SERVER POUR SHAREPOINT CONFIGURER LA COLLATION SQL SERVER POUR SHAREPOINT par JeremyJeanson
Note : Je poste cet article à titre de pense-bête. Cela fait des années que je me trimballe avec une capture d'écran, car je ne me rappel jamais comment choisir la collation d'un SQL Server pour SharePoint. Pour SharePoint, il est conseillé de choisir la ...
Cliquez pour lire la suite de l'article par JeremyJeanson ETENDRE LE TEAM WEB ACCESS DE TFS 2012 - STEP 1: CRéATION DU PLUGINETENDRE LE TEAM WEB ACCESS DE TFS 2012 - STEP 1: CRéATION DU PLUGIN par Philess
Dans cet article nous allons créer un plugin installable sur le Team Web Access qui s'intègrera dans l'architecture du site et se chargera au moment où on le décidera.
Avant de lire ce billet et si cela n'est pas encore fait j...
Cliquez pour lire la suite de l'article par Philess
Logiciels
Nego Facturation (1.85)NEGO FACTURATION (1.85)Nego Facturation est un logiciel complet qui permet de gérer vos factures et devis très simplemen... Cliquez pour télécharger Nego Facturation Devis-Factures PHMSD (2.2.0.1)DEVIS-FACTURES PHMSD (2.2.0.1)Configuration minimale
Nécessite Windows™ 2000, XP, Windows 7, 8, Vista (Service Pack à... Cliquez pour télécharger Devis-Factures PHMSD WDmemoCode (2.0.0.1)WDMEMOCODE (2.0.0.1)WDmemoCode a été conçu pour aider les développeurs Windev à créer/compléter et conserver une base... Cliquez pour télécharger WDmemoCode ProtoMedic (4.0.0.11)PROTOMEDIC (4.0.0.11)ProtoMedic est un logiciel destiné principalement aux médecins généralistes.
ProtoMedic permet d... Cliquez pour télécharger ProtoMedic MyCurriculum 2011 (7.4.1.12)MYCURRICULUM 2011 (7.4.1.12)Rédigez votre Curriculum Vitae mais également ceux de votre famille ou de vos amis très facilemen... Cliquez pour télécharger MyCurriculum 2011
|