Page 487 - Beginning PHP 5.3
P. 487
Chapter 15: Making Your Job Easier with PEAR
echo “. Your operating system is “ . $detect->getOSString() . “.</p>”;
?>
</body>
</html>
Run the script by visiting its URL in your Web browser. You should see a result similar to Figure 15-1.
Figure 15-1
How It Works
This simple script kicks off with the standard XHTML page header, then includes the Net_
UserAgent_Detect package:
require_once( “Net/UserAgent/Detect.php” );
Next it creates a new Net_UserAgent_Detect object:
$detect = new Net_UserAgent_Detect();
The Net_UserAgent_Detect class contains a number of different methods for extracting browser
information. In this script, the getBrowserString() method is used to retrieve the visitor’s browser
name and version as a text string, and getOSString() is called to return the visitor’s operating
system as a string. These strings are then displayed in the page:
echo “<p>You are running “ . $detect->getBrowserString();
echo “. Your operating system is “ . $detect->getOSString() . “.</p>”;
449
9/21/09 9:14:49 AM
c15.indd 449
c15.indd 449 9/21/09 9:14:49 AM