Recupération infos du visiteur de ma page

Fermé
Evalon Messages postés 66 Date d'inscription mercredi 30 septembre 2015 Statut Membre Dernière intervention 21 juillet 2017 - 20 août 2016 à 20:50
Evalon Messages postés 66 Date d'inscription mercredi 30 septembre 2015 Statut Membre Dernière intervention 21 juillet 2017 - 23 août 2016 à 08:54
Bonjour a tous,

Je suis en train de faire un site et j'ai trouvé sur codes-sources.commentcamarche.net le script ci-dessous que j'ai mis en place sur une page de test index.php avec ces 2 includes

<?php include('infos.lib.php'); ?>
<?php  log_infos('Log/log.txt'); ?>


Voilà le script
<?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 detecté
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 detecté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 detecté)
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 (
							'Trident\/7.0' 		=> 'Internet Explorer 11',
							'Beamrise'			=> 'Beamrise',
							'Opera' 			=> 'Opera',
							'OPR' 				=> 'Opera',
							'Shiira' 			=> 'Shiira',
							'Chimera' 			=> 'Chimera',
							'Phoenix' 			=> 'Phoenix',
							'Firebird' 			=> 'Firebird',
							'Camino' 			=> 'Camino',
							'Netscape' 			=> 'Netscape',
							'OmniWeb' 			=> 'OmniWeb',
							'Konqueror' 		=> 'Konqueror',
							'icab' 				=> 'iCab',
							'Lynx' 				=> 'Lynx',
							'Links' 			=> 'Links',
							'hotjava' 			=> 'HotJava',
							'amaya' 			=> 'Amaya',
							'IBrowse' 			=> 'IBrowse',
							'iTunes' 			=> 'iTunes',
							'Silk' 				=> 'Silk',
							'Dillo' 			=> 'Dillo', 
							'Maxthon' 			=> 'Maxthon',
							'Arora' 			=> 'Arora',
							'Galeon' 			=> 'Galeon',
							'Iceape' 			=> 'Iceape',
							'Iceweasel' 		=> 'Iceweasel',
							'Midori' 			=> 'Midori',
							'QupZilla' 			=> 'QupZilla',
							'Namoroka' 			=> 'Namoroka',
							'NetSurf' 			=> 'NetSurf',
							'BOLT' 				=> 'BOLT',
							'EudoraWeb'			=> 'EudoraWeb',
							'shadowfox' 		=> 'ShadowFox',
							'Swiftfox' 			=> 'Swiftfox',
							'Uzbl' 				=> 'Uzbl',
							'UCBrowser' 		=> 'UCBrowser',
							'Kindle' 			=> 'Kindle',
							'wOSBrowser' 		=> 'wOSBrowser',
							'Epiphany' 			=> 'Epiphany', 
							'SeaMonkey' 		=> 'SeaMonkey',
							'Avant Browser' 	=> 'Avant Browser',
							'Firefox' 			=> 'Firefox',
							'[/download/telecharger-34056452-google-chrome Chrome]' 			=> '[/download/telecharger-34056452-google-chrome Google Chrome]',
							'MSIE' 				=> 'Internet Explorer',
							'Internet Explorer' => 'Internet Explorer',
							'Edge' 				=> 'Edge',							
							'Safari' 			=> 'Safari',
							'Mozilla' 			=> 'Mozilla',
							'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="1" 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, 'a')){
  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                        //
//----------------------------------------------------------------//

?>

Je le trouve super sympa mais sa dernière mis a jour date du 29/10/2006 donc il manque quelques OS, les appareils mobile et mon niveau en Php laisse grandement à désirer pour pouvoir le finir tout seul.

J'ai réussi a rajouter "Google Chrome" pour les navigateurs en rajoutant la ligne
'Chrome'            => 'Google Chrome',

Mais pour le nouveau navigateur de Windows, notre petit Edge, il n'y as pas moyen.

Et pour les OS c'est une autre paire de manche car même si je rajoute
'(win|windows) ?(10)'      => 'Windows 10',
        '(win|windows) ?(8.1)'         => 'Windows 8.1',
        '(win|windows) ?(8)'           => 'Windows 8',
        '(win|[/contents/1397-windows-7-introduction windows) ?(7])'           => 'Windows 7',

Cela ne marche pas il manque également les Os mobiles que je n'arrive pas non plus à rajouter

Voilà j'y ai passé toute la journée de hier et je n'est rajouté que Chrome (heureusement que c'est pour moi et que je suis pas payé au rendement)

J'espère que quelqu'un aura le courage d'y mettre le nez pour me filer un coup de main car je trouve que ce script est très sympa et même si il date de 10 ans je trouve ça dommage de le laisser tomber aux oubliettes

Merci d'avance
A voir également:

3 réponses

jordane45 Messages postés 38144 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 21 avril 2024 4 650
20 août 2016 à 23:18
Bonjour,
Tu peux t'appuyer sur différentes réponses données sur le net à ce sujet.
Par exemple :
https://stackoverflow.com/questions/18070154/get-operating-system-info

<?php

$user_agent     =   $_SERVER['HTTP_USER_AGENT'];

function getOS() { 

    global $user_agent;

    $os_platform    =   "Unknown OS Platform";

    $os_array       =   array(
                            '/windows nt 10/i'     =>  'Windows 10',
                            '/windows nt 6.3/i'     =>  'Windows 8.1',
                            '/windows nt 6.2/i'     =>  'Windows 8',
                            '/windows nt 6.1/i'     =>  'Windows 7',
                            '/windows nt 6.0/i'     =>  'Windows Vista',
                            '/windows nt 5.2/i'     =>  'Windows Server 2003/XP x64',
                            '/windows nt 5.1/i'     =>  'Windows XP',
                            '/windows xp/i'         =>  'Windows XP',
                            '/windows nt 5.0/i'     =>  'Windows 2000',
                            '/windows me/i'         =>  'Windows ME',
                            '/win98/i'              =>  'Windows 98',
                            '/win95/i'              =>  'Windows 95',
                            '/win16/i'              =>  'Windows 3.11',
                            '/macintosh|mac os x/i' =>  'Mac OS X',
                            '/mac_powerpc/i'        =>  'Mac OS 9',
                            '/linux/i'              =>  'Linux',
                            '/ubuntu/i'             =>  'Ubuntu',
                            '/iphone/i'             =>  'iPhone',
                            '/ipod/i'               =>  'iPod',
                            '/ipad/i'               =>  'iPad',
                            '/android/i'            =>  'Android',
                            '/blackberry/i'         =>  'BlackBerry',
                            '/webos/i'              =>  'Mobile'
                        );

    foreach ($os_array as $regex => $value) { 

        if (preg_match($regex, $user_agent)) {
            $os_platform    =   $value;
        }

    }   

    return $os_platform;

}


Tu peux aussi t'appuyer sur la class PHP Browser : https://github.com/cbschuld/Browser.php
0
Evalon Messages postés 66 Date d'inscription mercredi 30 septembre 2015 Statut Membre Dernière intervention 21 juillet 2017 3
20 août 2016 à 23:38
Je vais essayé ça merci
0
Evalon Messages postés 66 Date d'inscription mercredi 30 septembre 2015 Statut Membre Dernière intervention 21 juillet 2017 3
Modifié par Evalon le 22/08/2016 à 23:49
Bonsoir,

Désolé du retard, mais le boulot avant tout

J'ai réussi à ajouter les mobiles et les Windows manquant avec
 $array = array(
   // ---- Mobile ----  
                 '(android)'                         =>  'Android',
                 '(iphone)'                          =>  'iPhone',
                 '(ipod)'                             =>  'iPod',
                 '(ipad)'                             =>  'iPad',
                 '(blackberry)'                    =>  'BlackBerry',
                 '(webos)'                          =>  'Mobile',
           // ---- Desktop ----
                 // Windows
                 '(win|windows) ?NT (10)'            => 'Windows 10',     
                 '(win|windows) ?NT (8.1)'           => 'Windows 8.1',      
                 '(win|windows) ?NT (8)'             => 'Windows 8',     
                 '(win|windows) ?NT (7)'             => '[/contents/1397-windows-7-introduction Windows 7]',     


Par contre j'ai eu le temps, pour le moment, de vérifier le bon fonctionnement du script qu'avec Android, Iphone, Ipad et Windows 10.

Mais je me demandais s'il était plus judicieux de mettre en premier les vieux OS ou les neufs.

J'ai un souci par contre j'ai téléchargé les 6 Navigateurs principaux afin de faire des test et avec safari le code me renvoie un Windows XP au lieu de Windows 10

Et enfin une dernière question
Serait t'il possible d'ajouter les tailles d'écran ?

Merci
0
Evalon Messages postés 66 Date d'inscription mercredi 30 septembre 2015 Statut Membre Dernière intervention 21 juillet 2017 3
23 août 2016 à 08:54
Après quelques test j'ai du retouché le script pour les Windows

 
                 '(win|windows) ?NT (10)'            => 'Windows 10',				 
                 '(win|windows) ?NT ?(6(\.1)?)'      => 'Windows 8.1',					 
                 '(win|windows) ?NT ?(6(\2.9200)?)'  => 'Windows 8',				 
                 '(win|windows) ?NT ?(6(\.3)?)'      => 'Windows 7',


J'ai aussi réussi a ajouté les versions Android

    '(Android 1.5)'                     => 'Android 1.5 (Cupcake)',
    '(Android 2.0)'                     => 'Android 2.0 (Eclair)',
    '(Android 3.0)'                     => 'Android 3.0 (Honeycomb)',
    '(Android 4.0)'                     => 'Android 4.0 (Ice Cream Sandwich)',
    '(Android 4.1)'                     => 'Android 4.1 (Jelly Bean)',
    '(Android 4.2)'                     => 'Android 4.2 (Jelly Bean)',				 
    '(Android 4.3)'                     => 'Android 4.3 (Jelly Bean)',
    '(Android 4.4)'                     => 'Android 4.4 (KitKat)',				 
    '(Android 5.0)'                     => 'Android 5.0 (Lollipop)',
    '(Android 6.0)'                     => 'Android 6.0 (Marshmallow)',
    '(Android 7.0)'                     => 'Android 7.0 (Nougat)',
    '(Android)'                           => 'Android',


Mais pour Iphone cela ne marche pas
                 '(iphone OS 2.0)'                   => 'iPhone 3G',
                 '(iphone OS 3.0)'                   => 'iPhone 3GS',
                 '(iphone iOS 4.0)'                  => 'iPhone 4',
                 '(iphone iOS 5.0)'                  => 'iPhone 4s',
                 '(iphone iOS 6.0)'                  => 'iPhone 5',
                 '(iphone iOS 7.0)'                  => 'iPhone 5c',
                 '(iphone iOS 8.0)'                  => 'iPhone 6',
                 '(iphone iOS 9.0)'                  => 'iPhone 6s',	 
                 '( iOS 9.3)'                        => 'iPhone SE',
                 '(iphone)'                          => 'iPhone',


Pour les macs (Mais pas encore vérifié)

	// Macintosh
        '(mac os x beta)'                   => 'Mac OSX Beta (Kodiak)',
        '(mac os x 10.0)'                   => 'Mac OSX Cheetah',  
        '(mac os x 10.1)'                   => 'Mac OSX Puma', 
        '(mac os x 10.2)'                   => 'Mac OSX Jaguar',
        '(mac os x 10.3)'                   => 'Mac OSX Panther',
        '(mac os x 10.4)'                   => 'Mac OSX Tiger',
        '(mac os x 10.5)'                   => 'Mac OSX Leopard',
        '(mac os x 10.6)'                   => 'Mac OSX Snow Leopard',
        '(mac os x 10.7)'                   => 'Mac OSX Lion',
        '(mac os x)'                        => 'Mac OSX (Version Inconnue)',
        '(Macintosh|PPC)'                   => 'Macintosh',				 
        '(mac|ppc)'                         => 'Macintosh',


Et pour les linux cela ne marche pas non plus

			  // Linux
                 '(fedora)'                          => 'Linux - Fedora',
                 '(kubuntu'                          => 'Linux - Kubuntu',
                 '(ubuntu)'                          => 'Linux - Ubuntu',
                 '(debian)'                          => 'Linux - Debian',
                 '(CentOS)'                          => 'Linux - CentOS',
                 '(Mandriva).([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?)'   => 'Linux - Mandriva',
                 '(SUSE).([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?)'       => 'Linux - SUSE',
                 '(Dropline)'                        => 'Linux - Slackware (Dropline GNOME)',
                 '(ASPLinux)'                        => 'Linux - ASPLinux',
                 '(Red Hat)'                         => 'Linux - Red Hat',
                 '(linux)'                           => 'Linux',



Si quelqu'un avait une idée

Merci d'avance
0