home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / httpuseragent.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  4.1 KB  |  124 lines

  1. HTTP_USER_AGENT pars 
  2.  
  3.  
  4. A slightly modified version of the "Cloaking Variables" written by Leon Atkinson. It now properly parses for Netscape Navigator, Internet Explorer AND Opera (rather popular in Europe and a good "base-line" browser). The original code says it's 2.0 compatible, but I have only tested it in PHP 3.0. 
  5.  
  6. <? 
  7.      /***************************************************************/ 
  8.      /*Code: PHP 2                                                  */ 
  9.      /*Author: Leon Atkinson <leon@clearink.com>                    */ 
  10.      /***************************************************************/ 
  11.  
  12.      /* Get the name the browser calls itself and what version */ 
  13.     $Browser_Name = strtok($HTTP_USER_AGENT,  "/"); 
  14.     $Browser_Version = strtok( " "); 
  15.      
  16.      /* MSIE lies about its name */ 
  17.     if(ereg( "MSIE", $HTTP_USER_AGENT)) 
  18.     { 
  19.         $Browser_Name =  "MSIE"; 
  20.         $Browser_Version = strtok( "MSIE"); 
  21.         $Browser_Version = strtok( " "); 
  22.         $Browser_Version = strtok( ";"); 
  23.     } 
  24.      
  25.      /* Opera isn't completely honest, either ... */ 
  26.      /* Modificaton by Chris Mospaw <mospaw@polk-county.com> */ 
  27.     if(ereg( "Opera", $HTTP_USER_AGENT)) 
  28.     { 
  29.         $Browser_Name =  "Opera"; 
  30.         $Browser_Version = strtok( "Opera"); 
  31.         $Browser_Version = strtok( "/"); 
  32.         $Browser_Version = strtok( ";"); 
  33.     } 
  34.  
  35.      /* try to figure out what platform, windows or mac */ 
  36.     $Browser_Platform =  "unknown"; 
  37.     if(ereg( "Windows",$HTTP_USER_AGENT) ||  
  38.         ereg( "WinNT",$HTTP_USER_AGENT) || 
  39.         ereg( "Win95",$HTTP_USER_AGENT)) 
  40.     { 
  41.         $Browser_Platform =  "Windows"; 
  42.     } 
  43.      
  44.     if(ereg( "Mac", $HTTP_USER_AGENT)) 
  45.     { 
  46.         $Browser_Platform =  "Macintosh"; 
  47.     } 
  48.  
  49.      /* set the JavaScript and CSS properties */ 
  50.  
  51.      /* JavaScriptOK means that the browser understands JavaScript on       */ 
  52.      /* the same level the Navigator 3 does.  Most importantly, it can use  */ 
  53.      /* named images.  If a browser doesn't do this (Nav 2 or MSIE 3), then */ 
  54.      /* we just assume it can't do any JavaScript.  Referencing images by   */ 
  55.      /* load order is too hard to maintain.                                 */ 
  56.  
  57.      /* CSSOK is kind of sketchy in that Nav 4 and MSIE work differently,   */ 
  58.      /* but they do seem to have most of the functionality.  MSIE 4 for the */ 
  59.      /* Mac has buggy CSS support, so we let it do JavaScript, but no CSS.  */ 
  60.  
  61.      /* Support for UNIX browser could be useful.                           */ 
  62.      
  63.     $Browser_JavaScriptOK = 0; 
  64.     $Browser_CSSOK = 0; 
  65.  
  66.     if(($Browser_Platform ==  "Windows")) 
  67.     { 
  68.         if($Browser_Name ==  "Mozilla") 
  69.         { 
  70.             if($Browser_Version >= 3.0) 
  71.             { 
  72.                 $Browser_JavaScriptOK = 1; 
  73.             }         
  74.             if($Browser_Version >= 4.0) 
  75.             { 
  76.                 $Browser_CSSOK = 1; 
  77.             } 
  78.         } 
  79.         else  /* must be MSIE */ 
  80.         { 
  81.             if($Browser_Version >= 4.0) 
  82.             { 
  83.                 $Browser_JavaScriptOK = 1; 
  84.                 $Browser_CSSOK = 1; 
  85.             }         
  86.         } 
  87.     } 
  88.     else  /* must be mac */ 
  89.     { 
  90.         if($Browser_Name ==  "Mozilla") 
  91.         { 
  92.             if($Browser_Version >= 3.0) 
  93.             { 
  94.                 $Browser_JavaScriptOK = 1; 
  95.             }         
  96.             if($Browser_Version >= 4.0) 
  97.             { 
  98.                 $Browser_CSSOK = 1; 
  99.             } 
  100.         } 
  101.         else  /* must be MSIE */ 
  102.         { 
  103.             if($Browser_Version >= 4.0) 
  104.             { 
  105.                 $Browser_JavaScriptOK = 1; 
  106.             }         
  107.         } 
  108.     } 
  109. ?> 
  110.  
  111. <HTML> 
  112. <BODY> 
  113.  
  114. Full $HTTP_USER_AGENT:  <? echo $HTTP_USER_AGENT; ?><BR> 
  115. Browser_Name:  <? echo $Browser_Name; ?><BR> 
  116. Browser_Version:  <? echo $Browser_Version; ?><BR> 
  117. Browser_Platform:  <? echo $Browser_Platform; ?><BR> 
  118. Browser_JavaScriptOK:  <? echo $Browser_JavaScriptOK; ?><BR> 
  119. Browser_CSSOK:  <? echo $Browser_CSSOK; ?><BR> 
  120.  
  121.  
  122. </BODY> 
  123. </HTML> 
  124.