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

  1. Cloaking Variables 
  2.  
  3. Parses HTTP_USER_AGENT so that you can customize your site to different browsers. 
  4.  
  5.  
  6.  
  7. <?php 
  8.      /* 
  9.     ** Cloaking Variables  
  10.     ** Version 2.1 
  11.     ** Leon Atkisnon <leon@clearink.com> 
  12.     ** with contributions from: 
  13.     **    Chris Mospaw <mospaw@polk-county.com> 
  14.     **    Benjamin Elijah Griffin <bgriffin@cddb.com> 
  15.     ** 
  16.     ** This bit of code parses HTTP_USER_AGENT and sets the following variables: 
  17.     ** Browser_Name 
  18.     ** Browser_Version 
  19.     ** Browser_Platform 
  20.     ** Browser_JavaScriptOK 
  21.     ** Browser_CSSOK 
  22.     ** Browser_TextOnly 
  23.     ** Browser_FileUpload 
  24.     ** 
  25.     ** JavaScriptOK means that the browser understands JavaScript on        
  26.     ** the same level the Navigator 3 does.  Specifically, it can use   
  27.     ** named images.  This allows easier rollovers.  If a browser doesn't 
  28.     ** do this (Nav 2 or MSIE 3), then we just assume it can't do any  
  29.     ** JavaScript.  Referencing images by load order is too hard to maintain.                                  
  30.     ** 
  31.     ** CSSOK is kind of sketchy in that Nav 4 and MSIE work differently,    
  32.     ** but they do seem to have most of the functionality.  MSIE 4 for the  
  33.     ** Mac has buggy CSS support, so we let it do JavaScript, but no CSS.   
  34.     */ 
  35.  
  36.      // Get the name the browser calls itself and what version 
  37.     $Browser_Name = strtok($HTTP_USER_AGENT,  "/"); 
  38.     $Browser_Version = strtok( " "); 
  39.      
  40.      // MSIE lies about its name 
  41.     if(ereg( "MSIE", $HTTP_USER_AGENT)) 
  42.     { 
  43.         $Browser_Name =  "MSIE"; 
  44.         $Browser_Version = strtok( "MSIE"); 
  45.         $Browser_Version = strtok( " "); 
  46.         $Browser_Version = strtok( ";"); 
  47.     } 
  48.  
  49.      // Opera isn't completely honest, either ... 
  50.      // Modificaton by Chris Mospaw <mospaw@polk-county.com> 
  51.     if(ereg( "Opera", $HTTP_USER_AGENT)) 
  52.     { 
  53.         $Browser_Name =  "Opera"; 
  54.         $Browser_Version = strtok( "Opera"); 
  55.         $Browser_Version = strtok( "/"); 
  56.         $Browser_Version = strtok( ";"); 
  57.     } 
  58.  
  59.  
  60.      // try to figure out what platform, windows or mac 
  61.     $Browser_Platform =  "unknown"; 
  62.     if(ereg( "Windows",$HTTP_USER_AGENT) ||  
  63.         ereg( "WinNT",$HTTP_USER_AGENT) || 
  64.         ereg( "Win98",$HTTP_USER_AGENT) || 
  65.         ereg( "Win95",$HTTP_USER_AGENT)) 
  66.     { 
  67.         $Browser_Platform =  "Windows"; 
  68.     } 
  69.      
  70.     if(ereg( "Mac", $HTTP_USER_AGENT)) 
  71.     { 
  72.         $Browser_Platform =  "Macintosh"; 
  73.     } 
  74.  
  75.     if(ereg( "X11", $HTTP_USER_AGENT))  
  76.     {  
  77.         $Browser_Platform =   "Unix";  
  78.     }  
  79.  
  80.      //default to no JavaScript or CSS support 
  81.     $Browser_JavaScriptOK = FALSE; 
  82.     $Browser_CSSOK = FALSE; 
  83.     $Browser_FileUpload = FALSE; 
  84.  
  85.     if($Browser_Platform ==  "Windows") 
  86.     { 
  87.         if($Browser_Name ==  "Mozilla") 
  88.         { 
  89.             if($Browser_Version >= 3.0) 
  90.             { 
  91.                 $Browser_JavaScriptOK = TRUE; 
  92.                 $Browser_FileUpload = TRUE; 
  93.             }         
  94.             if($Browser_Version >= 4.0) 
  95.             { 
  96.                 $Browser_CSSOK = TRUE; 
  97.             } 
  98.         } 
  99.         elseif($Browser_Name ==  "MSIE") 
  100.         { 
  101.             if($Browser_Version >= 4.0) 
  102.             { 
  103.                 $Browser_JavaScriptOK = TRUE; 
  104.                 $Browser_FileUpload = TRUE; 
  105.                 $Browser_CSSOK = TRUE; 
  106.             }         
  107.         } 
  108.         elseif($Browser_Name ==  "Opera") 
  109.         { 
  110.             if($Browser_Version >= 3.0) 
  111.             { 
  112.                 $Browser_JavaScriptOK = TRUE; 
  113.                 $Browser_FileUpload = TRUE; 
  114.                 $Browser_CSSOK = TRUE; 
  115.             }         
  116.         } 
  117.     } 
  118.     elseif($Browser_Platform ==  "Macintosh") 
  119.     { 
  120.         if($Browser_Name ==  "Mozilla") 
  121.         { 
  122.             if($Browser_Version >= 3.0) 
  123.             { 
  124.                 $Browser_JavaScriptOK = TRUE; 
  125.                 $Browser_FileUpload = TRUE; 
  126.             }         
  127.             if($Browser_Version >= 4.0) 
  128.             { 
  129.                 $Browser_CSSOK = TRUE; 
  130.             } 
  131.         } 
  132.         elseif($Browser_Name ==  "MSIE") 
  133.         { 
  134.             if($Browser_Version >= 4.0) 
  135.             { 
  136.                 $Browser_JavaScriptOK = TRUE; 
  137.                 $Browser_CSSOK = TRUE; 
  138.                 $Browser_FileUpload = TRUE; 
  139.             }         
  140.         } 
  141.     } 
  142.     elseif($Browser_Platform ==   "Unix")  
  143.     {  
  144.         if($Browser_Name ==   "Mozilla")  
  145.         {  
  146.             if($Browser_Version >= 3.0)  
  147.             {  
  148.                 $Browser_JavaScriptOK = TRUE;  
  149.                 $Browser_FileUpload = TRUE;  
  150.             }          
  151.             if($Browser_Version >= 4.0)  
  152.             {  
  153.                 $Browser_CSSOK = TRUE;  
  154.             }  
  155.         }  
  156.     } 
  157.  
  158.      
  159. ?> 
  160.  
  161. <HTML> 
  162. <BODY> 
  163.  
  164. Browser_Name:  <? echo $Browser_Name; ?><BR> 
  165. Browser_Version:  <? echo $Browser_Version; ?><BR> 
  166. Browser_Platform:  <? echo $Browser_Platform; ?><BR> 
  167. Browser_JavaScriptOK:  <? echo $Browser_JavaScriptOK; ?><BR> 
  168. Browser_CSSOK:  <? echo $Browser_CSSOK; ?><BR> 
  169. Browser_FileUpload :  <? echo $Browser_FileUpload; ?><BR> 
  170.  
  171.  
  172.  
  173. </BODY> 
  174. </HTML> 
  175.  
  176.