Infos lib

Description

Plop all!
Voilà, j'viens de ressortir et réassortir ce script de mes archives ^^

InFos Lib sert à récupérer (à peu prés) toutes les infos utiles sur le client:
IP réelle, Host, Proxy, Host Proxy, Système d'exploitation, Navigateur, Langage navigateur, Referer, Uri..

Sa peut toujours servir et être amélioré à l'occasion ;)

Source / Exemple :


<?php

//----------------------------<++++++>---------------------------//
//                           InFoS LIB                           //
//---------------------------------------------------------------//
//           Retourne toutes les infos sur le visiteur           //
//     IP réelle, proxy, host, système, navigateur, langue...    //
//---------------------------------------------------------------//
//                       Coder par Minimix                       //
//                   minimix92<arobase>free.fr                   //
//----------------------------<++++++>---------------------------//

// >> Retourne l'ip réelle si un proxy est détecté
function proxy_detect(){
  $array = array('HTTP_X_FORWARDED_FOR','HTTP_X_FORWARDED','HTTP_FORWARDED_FOR','HTTP_FORWARDED',
                 'HTTP_VIA','HTTP_X_COMING_FROM','HTTP_COMING_FROM','HTTP_CLIENT_IP'            );
  foreach($array as $key){
    if(isset($_SERVER[$key]) && !empty($_SERVER[$key])) return $_SERVER[$key];}
  return NULL;
  }

// >> Retourne l'ip réelle (si elle est détectée)
function real_ip_detect(){
  if($real_ip = proxy_detect()) return $real_ip;
  else                          return $_SERVER['REMOTE_ADDR'];
  }

// >> Retourne l'host réelle (si il est détecté)
function real_host_detect(){
  if($real_ip = proxy_detect()) return @gethostbyaddr($real_ip);
  else                          return @gethostbyaddr($_SERVER['REMOTE_ADDR']);
  }

// >> Retourne l'IP du proxy (si elle est detectée)
function proxy_ip__detect(){
  if(proxy_detect()) return $_SERVER['REMOTE_ADDR'];
  else               return FALSE;
  }

// >> Retourne l'host du proxy (si il est detecté)
function proxy_host_detect(){
  if(proxy_detect()) return @gethostbyaddr($_SERVER['REMOTE_ADDR']);
  else               return FALSE;
  }

// >> Retourne le système d'exploitation (OS)
function system_detect(){
  $array = array('(win|windows) ?(9x ?4\.90|Me)'     => 'Windows ME',
                 '(win|windows) ?(98)'               => 'Windows 98',
                 '(win|windows) ?(2000)'             => 'Windows 2000',
                 '(win|windows) ?(95)'               => 'Windows 95',
                 '(win|windows) ?NT ?(5\.1|6(\.0)?)' => 'Windows XP',
                 '(win|windows) ?NT ?(5(\.0)?)'      => 'Windows NT',
                 '(win|windows) ?VISTA'              => 'Windows VISTA',
                 '(win|windows) ?XP ?(LSD)'          => 'Windows LSD',
                 '(win|windows) ?XP'                 => 'Windows XP',
                 '(win|windows)'                     => 'Windows',
                 '(linux)'                           => 'Linux',
                 'SunOs'                             => 'SunOs',
                 '(freebsd)'                         => 'FreeBSD',
                 '(openbsd)'                         => 'OpenBS',
                 '(netbsd)'                          => 'NetBSD',
                 '(AIX)'                             => 'AIX',
                 '(QNX)'                             => 'QNX',
                 '(HP-UX)'                           => 'HP-UX',
                 '(IRIX)'                            => 'IRIX',
                 '(unix|x11)'                        => 'UNIX',
                 '(Macintosh|PPC)'                   => 'Macintosh',
                 '(mac|ppc)'                         => 'Macintosh',
                 'beos'                              => 'BeOS',
                 'os/2'                              => 'OS/2'
                );
  foreach($array as $reg => $system){
  if(eregi($reg, $_SERVER['HTTP_USER_AGENT']))  return $system;}
  return 'Inconnu';
  }

// >> Retourne le navigateur
function browser_detect(){
  $array = array('(MSIE)'       => 'Internet Explorer',
                 '(Firefox)'    => 'Mozilla Firefox',
                 '(Mozilla)'    => 'Mozilla',
                 '(Opera)'      => 'Opera',
                 '(Netscape)'   => 'Netscape',
                 '(AOL)'        => 'AOL',
                 '(Konqueror)'  => 'Konqueror',
                 '(Lynx)'       => 'Lynx',
                 '(Amaya)'      => 'Amaya',
                 '(AvantGo)'    => 'AvantGo',
                 '(Bluefish)'   => 'Bluefish',
                 '(ICEBrowser)' => 'ICEBrowser',
                 '(Safari)'     => 'Safari',
                 '(Kanari)'     => 'Kanari',
                 '(ICEBrowser)' => 'ICEBrowser',
                 '(bot|google|slurp|scooter|spider|infoseek|arachnoidea|altavista)' => 'Search engine',
                 'tv'           => 'Web TV'
                );
  foreach($array as $reg => $browser){
  if(eregi($reg, $_SERVER['HTTP_USER_AGENT']))  return $browser;}
  return 'Inconnu';
  }

// >> Retourne le code language utilisé par l'explorateur
function language_detect(){
  $language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  $lang_list = array('AF','SQ','DE','EN','AR','AN','HY','AS','AST','AZ','EU','BN','BE','BS','BR','PTBR','BG','KM','CA','CH','ZH','KO','CO','HR','DA','ES','EO','ET','FJ','FI','FR','HT','HE','HU','HI','ID','GA','IS','IT','JA','LA','LT','MK','MS','MO','NL','NE','NO','PA','FA','PL','PT','RO','RU','SR','SRCYR','SK','SL','SV','CS','CE','TH','UK','VI','YI');
  $accept_lang = explode(',', $language);
  reset($accept_lang);
  while(list($index, $lang) = @each($accept_lang)) {
  if(eregi("^(.+);q=([0-9.]*)$", $lang, $reg))
  $accept_lang[$index] = $reg[2].';'.strtoupper($reg[1]);
  else
  $accept_lang[$index] = '1.0;'.strtoupper($accept_lang[$index]); }
  arsort($accept_lang);
  reset($accept_lang);
  while(list(, $alang) = @each($accept_lang)) {
  reset($lang_list);
  while(list(, $lng) = @each($lang_list)) {
  if(strpos($alang, $lng)!=0) {
  $the_lang = $lng;
  break 2; } } }
  unset($accept_lang, $alang, $lng);
  return $the_lang;
  }

// >> Retourne la langue par rapport à son code
function language_convert($lang=''){
  $array = array('AF'   => 'Afrikaans',
                 'SQ'   => 'Albanais',
                 'DE'   => 'Allemand',
                 'EN'   => 'Anglais',
                 'AR'   => 'Arabe',
                 'AN'   => 'Aragonais',
                 'HY'   => 'Arménien',
                 'AS'   => 'Assamais',
                 'AST'  => 'Asturien',
                 'AZ'   => 'Azéri',
                 'EU'   => 'Basque',
                 'BN'   => 'Bengali',
                 'BE'   => 'Biélorusse',
                 'BS'   => 'Bosniaque',
                 'PTBR' => 'Brézil',
                 'BR'   => 'Brézil',
                 'BG'   => 'Bulgare',
                 'KM'   => 'Cambodgien',
                 'CA'   => 'Catalan',
                 'CH'   => 'Chamaroo',
                 'ZH'   => 'Chinois',
                 'KO'   => 'Coréen',
                 'CO'   => 'Corse',
                 'HR'   => 'Croate',
                 'DA'   => 'Danois',
                 'ES'   => 'Espagnol',
                 'EO'   => 'Espéranto',
                 'ET'   => 'Estonien',
                 'FJ'   => 'Fidjien',
                 'FR'   => 'Français',
                 'HT'   => 'Haïtien',
                 'HE'   => 'Hébreu',
                 'HU'   => 'Hongrois',
                 'HI'   => 'Hindi',
                 'ID'   => 'Indonésien',
                 'GA'   => 'Irlandais',
                 'IS'   => 'Islandais',
                 'IT'   => 'Italien',
                 'JA'   => 'Japonais',
                 'LA'   => 'Latin',
                 'LT'   => 'Lituanien',
                 'MK'   => 'Macédoine',
                 'MS'   => 'Malais',
                 'MO'   => 'Moldave',
                 'NL'   => 'Néerlandais',
                 'NE'   => 'Népalais',
                 'NO'   => 'Norvégiens',
                 'PA'   => 'Penjabi',
                 'FA'   => 'Persan',
                 'PL'   => 'Polonais',
                 'PT'   => 'Portuguais',
                 'RO'   => 'Roumain',
                 'RU'   => 'Russe',
                 'SRCYR'=> 'Serbe',
                 'SR'   => 'Serbe',
                 'SK'   => 'Slovaque',
                 'SL'   => 'Slovène',
                 'SV'   => 'Suédois',
                 'CS'   => 'Tchèque',
                 'CE'   => 'Tchétchène',
                 'TH'   => 'Thaï',
                 'TR'   => 'Turque',
                 'UK'   => 'Ukrainien',
                 'VI'   => 'Vietnamien',
                 'YI'   => 'Yiddish',
                );
  foreach($array as $reg => $language){
  if($lang == $reg)  return $language;}
  return 'Inconnu';
  }

// >> Retourne le port d'écoute
function port_detect(){
  if(!empty($_SERVER['REMOTE_PORT'])) return $_SERVER['REMOTE_PORT'];
  else                                return 'Inconnu';
  }

// >> Retourne la provenance
function referer_detect(){
  if(!empty($_SERVER['HTTP_REFERER'])) return $_SERVER['HTTP_REFERER'];
  else                                 return 'Inconnu';
  }

// >> Retourne le lien demandé
function uri_detect(){
  if(!empty($_SERVER['REQUEST_URI'])) return 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  else                                return 'Inconnu';
  }

// >> Affiche les infos client
function view_infos_client(){
  $info = proxy_detect();
  echo '<style>';
  echo 'body { background-color:#CCCCCC; font-family:Courier new; font-weight:bold; text-align:center; }';
  echo 'th { background-color:#999999; border:1px solid #2D2D2D; color:#2D2D2D; font-family:Courier New; font-size:15px; font-weight:bold; text-align:center; }';
  echo 'td { background-color:#2D2D2D; color:#FFFFFF; font-family:"Lucida Console", Courier, monospace; font-size:13px; }';
  echo '</style>';
  echo '<br />';
  echo '<br />';
  echo '<table align="center" border="0" cellpadding="4" cellspacing="0">';
  echo '<tbody>';
  echo '<tr><th colspan="2"><u>Le '.date('d/m/Y').' à '.date('H:i:s').'</u></th></tr>';
  if(!empty($info)){
  echo '<tr><td><b>Proxy IP</b></td><td align="left">: ' .proxy_ip__detect().  '</td></tr>';
  echo '<tr><td><b>Hostname</b></td><td align="left">: ' .proxy_host_detect(). '</td></tr>'; }
  echo '<tr><td><b>Real IP </b></td><td align="left">: ' .real_ip_detect().    '</td></tr>';
  echo '<tr><td><b>Hostname</b></td><td align="left">: ' .real_host_detect().  '</td></tr>';
  echo '<tr><td><b>Port    </b></td><td align="left">: ' .port_detect().       '</td></tr>';
  echo '<tr><td><b>System  </b></td><td align="left">: ' .system_detect().     '</td></tr>';
  echo '<tr><td><b>Browser </b></td><td align="left">: ' .browser_detect().    '</td></tr>';
  echo '<tr><td><b>Language</b></td><td align="left">: ' .language_convert(language_detect()). '</td></tr>';
  echo '<tr><td><b>Referer </b></td><td align="left">: ' .referer_detect().    '</td></tr>';
  echo '<tr><td><b>Uri     </b></td><td align="left">: ' .uri_detect().        '</td></tr>';
  echo '</tbody>';
  echo '</table>';
  echo '<br />';
  echo '<br />';
  echo '- InFoS LIB - <br />';
  echo '- Coded by Minimix -';
  }

// >> Recupère les infos client dans le fichier $log_file
function log_infos($log_file){
  if($fp = @fopen($log_file, 'w')){
  unset($info);
  $info = proxy_detect();
  $buf  = "Le ".date('d/m/Y')." à ".date('H:i:s')."\n\n";
  if(!empty($info)){
  $buf .= "Proxy IP : " .proxy_ip__detect().  "\n";
  $buf .= "Hostname : " .proxy_host_detect(). "\n"; }
  $buf .= "Real IP  : " .real_ip_detect().    "\n";
  $buf .= "Hostname : " .real_host_detect().  "\n";
  $buf .= "Port     : " .port_detect().       "\n";
  $buf .= "System   : " .system_detect().     "\n";
  $buf .= "Browser  : " .browser_detect().    "\n";
  $buf .= "Language : " .language_convert(language_detect()). "\n";
  $buf .= "Referer  : " .referer_detect().    "\n";
  $buf .= "Uri      : " .uri_detect().        "\n";
  if(@fputs($fp, $buf)) {
  @fclose($fp);
  return TRUE; }}
  @fclose($fp);
  return FALSE;
  }

//----------------------------<++++++>----------------------------//
//                        EnD Of InFoS LIB                        //
//----------------------------------------------------------------//

?>

Conclusion :


Utilisation:

include('infos.lib.php');

// Affiche toutes les infos à savoir sur le client
view_infos_client();

// Affiche l'IP du proxy si elle est detectée
if($proxy_ip = proxy_ip__detect())
echo "Proxy IP : $proxy_ip<br />";

// Affiche la "vraie" IP si elle est detectée
if($real_ip = real_ip_detect())
echo "Real IP : $real_ip<br />";

// ...

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.