<?php

require 'browserhawk.php';

  // This sample is provided under the terms of the BrowserHawk End User
  // License Agreement.  Copyright (c) 2003-2006 cyScape, Inc. All rights
  // reserved.

  // This sample demonstrates how to dynamically enumerate the BrowserHawk
  // properties to return a page showing all BrowserHawk detected results.

  // To demonstrate, we dynamically enumerate all the properties and display a
  // table with each property's value.  There are two tables displayed - one
  // for the "basic" properties as exposed through the BrowserInfo interface,
  // and another for the "extended" properties as exposed through the
  // ExtendedBrowserInfo class.

  // If we don't have an enterprise license, skip testing enterprise props to
  // avoid a run-time license error
  $isEnterprise = strpos($BrowserHawk->getVersion(), "Ent") >= 0;
  $isPro = strpos($BrowserHawk->getVersion(), "Pro") >= 0;

  // If Standard Edition then do not set up for or perform any extended
  // property tests, as these are not supported the Standard Edition.
  if ($isPro || $isEnterprise) {
     // Request a complete test.  This includes all extended properties that
     // are testable at the current BrowserHawk licensed edition.  That is,
     // a Professional license will test all Pro-level features while an
     // Enterprise license will test all Pro and Enterprise-level features.
     $options->addProperties("complete");

     // Assign a stable of ports to check
     $options->setPortsToCheck("80,443,554");

     // Some properties we'll test only if specifically requested
     $options->removeProperties("FontsInstalled, Plugin_Custom, PopupsBlocked, ConnectionSpeed, JavaVendor, JavaVersion, Plugin_JavaVer, MSJVMBuild, OSName, OSVersion, OSArch");

     // If the user sends a "doSpeed" parameter, we test speed detection
     if (isset($_GET["doSpeed"])) {
       $options->addProperties("ConnectionSpeed");
     }

     // If the user sends a "doJvmd" parameter and this is an Enterprise
     // Edition license, we test applet properties
     if (isset($_GET["doJvmd"]) && $isEnterprise) {
       $options->addProperties("JavaVendor, JavaVersion, Plugin_JavaVer, MSJVMBuild, OSName, OSVersion, OSArch");
     }

     // Now choose a request type; default is AUTO
     // See the documentation of the ExtendedOptions class for more
     // information on these request types and how they differ.
     // Note that in the majority of cases the default of REQUEST_TYPE_AUTO
     // is recommended.
     $options->setRequestType($options->REQUEST_TYPE_AUTO);

     // One common reason to use options is to set a "please wait" message.
     // Here we set the value to an explanation string, for purposes of
     // example.  The default is "".
     $options->setPageMessage(
       "Now determining extended properties of this browser, please wait...");

     // Comment in the following if JVMDetector.class is in a different
     // directory than this PHP, and specify where the class is to be found.
     //$options->setJVMCodeBase("/some/path/to/shared/files");

     $einfo = bhextended($options);
  }
?>

<HTML><HEAD>
<TITLE>BrowserHawk Sample - Full Browser Capabilities Test Page (PHP)</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF"><font face="arial">

<blockquote>
<h2>All BrowserHawk Properties Test Results</h2>

<FONT SIZE="+1">The following is information on your browser's capabilities<br>
as detected by 
<A HREF="http://www.cyscape.com/index.asp?q=showbrow">BrowserHawk</A>
(<?php echo $BrowserHawk->getVersion() ?>)

</FONT>
<P>

User agent: <?php echo $_SERVER['HTTP_USER_AGENT']; ?><p>
Browser Definition File version: <?php echo $info->getBDDVersion() ?>;
  Dated: <?php echo $info->getBDDDate() ?><p>

<?php
   $tdColor1 = "<TD font=arial BGCOLOR=#F0F0F0>";
   $tdColor2 = "<TD font=arial BGCOLOR=#FFFFFF>";
?>

   <TABLE BGCOLOR="#CCCCCC" BORDER=1 CELLPADDING=3 WIDTH=450>
   <TR><TD BGCOLOR="#99CCCC" COLSPAN=2 ALIGN=CENTER><FONT SIZE="5">
     Basic Properties for: <?php echo $info->getBrowser() ?> 
     <?php echo $info->getFullversion() ?>
     <?php echo $info->getPlatform() ?>
   </FONT></TD></TR>
   <TR><TD BGCOLOR="#FFFFCC"><B>&nbsp;Property</B></TD>
       <TD BGCOLOR="#FFFFCC"><B>&nbsp;Value</B></TD></TR>
<?php
   $colorCnt = 0;

   $basicProps = array( "Browser", "Majorver", "Minorver", "Minorverlet",
      "Version", "Fullversion", "Platform", "Gecko", "GeckoBuildDate", "Beta",
      "Frames", "IFrames", "Tables", "Cookies", "VBScript", "JavaScript",
      "JavaApplets", "ActiveXControls", "WinInstallerMinVer", "AOL",
      "AOLVersion", "SSL", "SSLActive", "SSLKeySize", "Win16", "Crawler",
      "CDF", "NETCLRInstalled", "NETCLRVersion", "Language",
      "AuthenticodeUpdate", "StyleSheets", "Proxy", "ProxyString",
      "OSDetails", "MSN", "Gold", "DHTML", "FileUpload", "MouseOver", "PNG",
      "FontColor", "FontSize", "TableBGColor", "JavaScriptVer", "IPAddr",
      "Country", "TableBGImage", "CompressGZip", "EmailCrawler", "XML", "WAP",
      "WAP_DeviceModel", "WAP_Gateway", "WAP_SubscriberID", "WAP_MaxDeckSize",
      "HDML", "PDA", "CharHeightAvail", "CharWidthAvail", "ContainerBrowser",
      "ContainerVersion", "ContainerFullversion", "XMLHttpRequest" );
   foreach ($basicProps as $propertyName) {
      $colorCnt++;
      if ($colorCnt % 2 == 0)
         $tdColorToUse = $tdColor1;
      else
         $tdColorToUse = $tdColor2;

      if ($propertyName == "WinInstallerMinVer" && $isEnterprise === false) { // special case
         $val = "Requires Enterprise Edition";
      }
      else if ($propertyName == "Country") { // special case
         // Normally we would try callin getCountry() and catch any exceptions
         // that indicate CountryHawk isn't available on this system.
         // However, using try/catch would bind us to PHP 5.  So as a 
         // workaround we'll peek at the $info->toString() to see if it
         // complains about "CountryHawk" being not available.  If it
         // complains, we know it's not present, and if not we're good to go.
         if (strpos($info->toString(), "CountryHawk") === false) {
            $val = $info->getCountry();
         }
         else {
            $val = "Requires <a href='http://www.cyscape.com/'>CountryHawk</a>";
         }
      }
      else {
         // Note: In this sample we are enumerating through all the basic
         // properties and dynamically accessing each of the properties
         // values through the get() method to make it convenient to display
         // all results.  However it is important to note that in normal
         // circumstances you would NOT use the get() method to get the
         // value since this returns the result as an object and is
         // internally less efficient.  Instead you should directly
         // reference the property you are interested in.
         // For instance use this:
         //     $browType = $info->getBrowser();    // do this
         //     $majorver = $info->getMajorver();   // do this
         // Instead of this:
         //     $browType = $info->get("Browser");  // not this
         //     $majorver = $info->get("Majorver"); // not this
         $val = $info->get($propertyName);
      }
      echo "<TR>${tdColorToUse}&nbsp;<a name=\"$propertyName\">$propertyName</a></TD>${tdColorToUse}&nbsp;";
      boolprint($val);
      echo "</TD></TR>";
   }
?>
   </TABLE>

   <P>
   <HR ALIGN=LEFT WIDTH=550>
   <P>

<?php
   if ($isPro || $isEnterprise) {
     // The PHP Java bridge doesn't let you compare complex Java objects for
     // equality, so we'll see if their toString() forms match.
     if ($einfo->toString() === $UNSUPPORTED->toString()) {
       echo "<big>No extended information is available.  Only Netscape, " .
            "Mozilla, IE, Opera and Safari clients are supported.</big><p>";
     }
     else if ($einfo->getJavaScriptEnabled() === false) {
       echo "<big>No extended information is available.  This client has " .
            "JavaScript disabled.</big><p>";
     }
   }
   // We'll print the table below regardless of the above warnings
?>


   <TABLE BGCOLOR="#CCCCCC" BORDER=1 CELLPADDING=3 WIDTH=500>
   <TR><TD BGCOLOR="#99CCCC" COLSPAN=2 ALIGN=CENTER><FONT SIZE="+2">Extended Properties</FONT></TD></TR>
   <TR><TD BGCOLOR="#FFFFCC"><B>&nbsp;Property</B></TD>
       <TD BGCOLOR="#FFFFCC"><B>&nbsp;Value</B></TD></TR>
<?php
   $colorCnt = 0;

   $extendedProps = array( "BrowserBuild", "ServicePack", "VBScriptEnabled",
      "VBScriptBuild", "JavaScriptEnabled", "JavaScriptBuild", "JavaEnabled",
      "JavaVersion", "JavaVendor", "MSJVMBuild", "ActiveXEnabled",
      "ImagesEnabled", "SSLEnabled", "SSLKeySize", "LangUser", "LangSystem",
      "TimeZoneDiff", "BrowserDateTime", "BrowserDateTimeMs", "Firewall",
      "FontSmoothing", "TextSize", "Height", "HeightAvail", "Width",
      "WidthAvail", "Broadband", "ConnectionType", "ConnectionSpeed",
      "Plugin_Flash", "Plugin_FlashVerEx", "Plugin_Director",
      "Plugin_DirectorVerEx", "Plugin_QuickTime", "Plugin_QuickTimeVerEx",
      "Plugin_Acrobat", "Plugin_AcrobatVerEx", "Plugin_RealPlayer",
      "Plugin_RealPlayerBuild", "Plugin_MediaPlayer", "Plugin_MediaPlayerVerEx",
      "Plugin_SVGViewer", "Plugin_CrystalReports", "Plugin_Viewpoint",
      "Plugin_Authorware", "Plugin_MapGuide", "Plugin_Citrix",
      "Plugin_JavaVer", "Plugin_Custom", "NetMeetingBuild", "ColorDepth",
      "MSXML", "OpenPorts", "Referrer", "PopupsBlocked", "FontsInstalled",
      "Plugin_IPIXViewer", "PersistentCookies", "SessionCookies",
      "HighSecurity", "OSName", "OSVersion", "OSArch", "ContainerBrowser",
      "ContainerVersion", "ContainerFullversion", "DisplayXDPIActual",
      "DisplayYDPIActual", "DisplayXDPILogical", "DisplayYDPILogical"
   );
   foreach ($extendedProps as $propertyName) {
      $colorCnt++;
      if ($colorCnt % 2 == 0)
         $tdColorToUse = $tdColor1;
      else
         $tdColorToUse = $tdColor2;

      // Basic default for Standard Edition licensees
      if (!$isPro && !$isEnterprise) {
         $val = "Not Available in Standard Edition";
      }
      // If this is a JVMD test and it's not set, let the user click
      else if (!isset($_GET["doJvmd"]) && $isEnterprise &&
              (
               $propertyName == "Plugin_JavaVer" ||
               $propertyName == "JavaVendor" ||
               $propertyName == "JavaVersion" ||
               $propertyName == "MSJVMBuild" ||
               $propertyName == "OSName" ||
               $propertyName == "OSArch" ||
               $propertyName == "OSVersion"
              )) {
         $val = "Click <a href=\"?doJvmd=1\">here</a> to test";
         // If isPro, intentionally fall through to translate()
      }
      else if ($propertyName == "ConnectionSpeed" && !isset($_GET["doSpeed"])) {
         $val = "Click <a href=\"?doSpeed=1\">here</a> to test";
      }
      else if ($propertyName == "PopupsBlocked" && $isEnterprise) {
         $val = "Click <a href=\"popupcheck.php\">here</a> to test";
      }
      else if ($propertyName == "FontsInstalled" && $isEnterprise) {
         $val = "Click <a href=\"fontcheck_adv.php\">here</a> to test";
      }
      else {
         $val = $einfo->translate($propertyName);
      }

      echo "<TR>${tdColorToUse}&nbsp;<a name=\"$propertyName\">$propertyName</a></TD>${tdColorToUse}&nbsp;$val</TD></TR>";
   }
?>

   </TABLE>

   <P>
   <HR>
   <P>

<b><a href="showbrow.php">Retry this test</a></b><P>
<b><a href="index.html">Return to list of other PHP samples</a></b><P>
<b><a href="http://www.cyscape.com/order/">BrowserHawk Pricing and Ordering</a></b><P>
<b><a href="http://www.cyscape.com/">cyScape home page</a></b><P>
</font>
</blockquote>
</body>
</html>
