|
|
|
| Title : |
Most of the browsers, especially Internet Explorer, behave in different ways. Hence it become necessary to use Browser detection to fix the non standard behavior of the browser. This is a browser sniffer class that can be used for the above purpose. |
| Categories : |
PHP, PHP Classes, Browsers |
 Sumit Agarwal |
| Date : |
Nov 24th 2007 |
| Grade : |
2 of 5 (graded 1 times) |
| Viewed : |
1153 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Sumit Agarwal |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
| <?php
class Browser {
function Browser(){
$ua = $_SERVER['HTTP_USER_AGENT'];
$os = (strpos($ua, 'Mac') !== false) ? 'MAC' : (strpos($ua, 'Win') !== false) ? 'WIN' : 'NIX';
$this->isOpera = (($pos = strpos($ua, 'Opera')) !== false);
if($this->isOpera){
$version = substr($ua, $pos + 6);
$this->isOpera7 = ($version >= 7);
$this->isOpera6 = ($version < 7);
}
$this->isIE = (!$this->isOpera && ($pos = strpos($ua, 'MSIE')) !== false);
if($this->isIE){
$version = substr($ua, $pos + 5);
$this->isIE6 = ($version >= 5.5);
$this->isIEWIN = (strpos($ua, 'Win') !== false);
$this->isIEMAC = (strpos($ua, 'Mac') !== false);
}
$this->isNN = (!$this->isOpera && !$this->isIE && ($pos = strpos($ua, 'Mozilla')) !== false);
if($this->isNN){
$version = substr($ua, $pos + 8);
$this->isNN6 = ($version >= 5);
$this->isNN4 = ($version == 4);
}
$this->isGecko = (strpos($ua, 'Gecko/200') !== false);
$this->isSafari = (strpos($ua, 'Safari') !== false);
}
}
?> | |
Usage Example
| <?
$b = new Browser();
echo '<script src="' . ($b->isIE ? 'ie' : 'nn') . '.js"></script>'
?> | | |
|
| Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs | | | PHP4 DirectoryIterator Class Categories : PHP, PHP Classes, Filesystem, Directories | | | Class to build a select tag in html, useful to build select boxes from a data base Categories : PHP, HTML and PHP, PHP Classes | | | Email Class Categories : PHP, Mail, PHP Classes | | | Customizable Calendar Class Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar | | | [PHP5] NOTIMEOUT PACKAGE Categories : PHP, PHP Classes, AJAX | | | Cool guestbook Categories : PHP, Complete Programs, PHP Classes | | | XPath for PHP without the DOM XML extension Categories : DOM XML, XML, XSLT, PHP Classes, PHP | | | MySQL Connection/Query Class Categories : Databases, MySQL, PHP, PHP Classes | | | Php Input Output Library - access the parallel and serial(rs232) port directly. Categories : PHP, Hardware, PHP Classes | | | Create and restore backup of MySQL databases Categories : MySQL, Databases, PHP, PHP Classes, Complete Programs | | | Vote-Poll script that has a wrapper class that allows the user to create
multiple polls on the same page with little trouble. Categories : PHP, PHP Classes, HTML and PHP | | | ElfReader: An ELF (Executable and Linking Format) header information in PHP. Shows how to use the UNPACK function to read data. Categories : PHP, Linux, PHP Classes | | | logger class (PHP5 +) Categories : PHP, PHP Classes, Log Files, XML | | | class formHTML build your HTML Forms from PHP Categories : PHP, PHP Classes, HTML and PHP, HTML | |
|
|
|