WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Automatic Browsers Detect
Categories : PHP, PHP Classes, Headers, Browsers
ROBERTO ALEMAN
Date : Feb 03rd 2010
Grade : 2 of 5 (graded 5 times)
Viewed : 4486
File : No file for this code example.
Images : No Images for this code example.
Search : More code by ROBERTO ALEMAN
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples 
Like this code?
Show the author your appreciation.
 

This class can be used to detect the current user browser.

It takes the user agent header value and returns the identification of the detected browser.

The class may also return the name of a CSS file or PHP script associated to the current browser.

index.php
<?php
/* 
class AutomaticBrowserDetect 0.1 by Roberto Aleman, you can use it with BSD Licence
Please use it, and report to me your experience for improvement the code in the next version */
include_once("automaticbrowsersdetect.php");
$newbrow = new AutomaticBrowsersDetect();
$newcss = new AutomaticBrowsersDetect();
$newurl = new AutomaticBrowsersDetect();

echo
"<center><h2>Your favorite browser is : ".$newbrow->GetBrow($_SERVER['HTTP_USER_AGENT'])."</h2><br/>";
echo
"<h2>I want Use this CSS styles : ".$newcss->checkcss($newbrow->GetBrow($_SERVER['HTTP_USER_AGENT']))."</h2><br/>"// show correct css file
echo "<h2>I want Use this URL to show my favorite web content with my CSS styles : ".$newurl->checkurl($newbrow->GetBrow($_SERVER['HTTP_USER_AGENT']))."</h2>";    // show correct destination url

echo "<br/><br/>by Roberto Aleman, you can use it with BSD Licence<br/>Please use it, and report to me your experience for improvement the code in the next version</center>";
/* AND NOW BY EXAMPLE, YOU CAN REDIRECT TO YOU PREFER URL ACCORD THE USER AGENT!!! ENJOY!! */

?>



automaticbrowsersdetect.php
<?php 
/* 
class AutomaticBrowsersDetect 0.1 by Roberto Aleman, you can use it with BSD Licence
Please use it, and report to me your experience for improvement the code in the next version */
class AutomaticBrowsersDetect{

function
GetBrow($ua) {
     
$bws = array(
           
'Flock' => '(Mozilla)(Gekco)(Firefox)',
           
'Chrome' =>'Chrome',
           
'Safari' =>'Safari',
           
'Opera' => 'Opera'
           
'MobileSafari'=> 'Apple', //iphone
           
'Opera Mini' => 'Opera Mini', //mobile phones with wap services
           
'Android' => 'Android', //android and nokia Nseries
           
'Mozilla Firefox'=> '(Firebird)|(Firefox)'
           
'Galeon' => 'Galeon'
           
'Mozilla'=>'Gecko'
           
'MyIE'=>'MyIE'
           
'Lynx' => 'Lynx'
           
'Netscape' => '(Mozilla/4\.75)|(Netscape6)|(Mozilla/4\.08)|(Mozilla/4\.5)|(Mozilla/4\.6)|(Mozilla/4\.79)'
           
'Konqueror'=>'Konqueror'
           
'Internet Explorer 8' => '(MSIE 8\.[0-9]+)'
           
'Internet Explorer 7' => '(MSIE 7\.[0-9]+)'
           
'Internet Explorer 6' => '(MSIE 6\.[0-9]+)'
           
'Internet Explorer 5' => '(MSIE 5\.[0-9]+)'
           
'Internet Explorer 4' => '(MSIE 4\.[0-9]+)'
); 
 
foreach(
$bws as $bw=>$mdl){ 
        if (
eregi($mdl, $ua))
        return
$bw
     } 
return
'UnKnow'


function
checkcss($brow){
   
         
$css = array(
           
'Flock' => 'Flock.css',
           
'Chrome' =>'Chrome.css',
           
'Safari' =>'Safari.css',
           
'Opera' => 'Opera.css',
           
'MobileSafari'=> 'Apple.css', //iphone
           
'Opera Mini' => 'OperaMini.css', //mobile phones with wap services
           
'Android' => 'Android.css', //android and nokia Nseries
           
'Mozilla Firefox'=> 'Firefox.css'
           
'Galeon' => 'Galeon.css'
           
'Mozilla'=>'Gecko.css'
           
'MyIE'=>'MyIE.css'
           
'Lynx' => 'Lynx.css'
           
'Netscape' => 'Netscape.css'
           
'Konqueror'=>'Konqueror.css'
           
'Internet Explorer 8' => 'ie8.css'
           
'Internet Explorer 7' => 'ie7.css'
           
'Internet Explorer 6' => 'ie6.css'
           
'Internet Explorer 5' => 'ie5.css'
           
'Internet Explorer 4' => 'ie4.css',
           );
foreach(
$css as $k => $v) {
   if(
$brow == $k){
   return
$v; }
}
}

function
checkurl($brow)
{
     
           
$url = array(
           
'Flock' => 'Flock.php',
           
'Chrome' =>'Chrome.php',
           
'Safari' =>'Safari.php',
           
'Opera' => 'Opera.php',
           
'MobileSafari'=> 'Apple.php', //iphone
           
'Opera Mini' => 'OperaMini.php', //mobile phones with wap services
           
'Android' => 'Android.php', //android and nokia Nseries
           
'Mozilla Firefox'=> 'Firefox.php'
           
'Galeon' => 'Galeon.php'
           
'Mozilla'=>'Gecko.php'
           
'MyIE'=>'MyIE.php'
           
'Lynx' => 'Lynx.php'
           
'Netscape' => 'Netscape.php'
           
'Konqueror'=>'Konqueror.php'
           
'Internet Explorer 8' => 'ie8.php'
           
'Internet Explorer 7' => 'ie7.php'
           
'Internet Explorer 6' => 'ie6.php'
           
'Internet Explorer 5' => 'ie5.php'
           
'Internet Explorer 4' => 'ie4.php',
           );
foreach(
$url as $k => $v) {
   if(
$brow == $k){
   return
$v; }
}

}

 
}
?>



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
Request Method Class - seful for situations like form processing or API development. Requires PHP5 for the magic __call() method.
Categories : PHP, PHP Classes, HTTP, Headers
Database and Recordset classes fo SyBASE Usage is obvious.
Categories : Sybase, Databases, PHP Classes, PHP
The Ajax Tree view class fetches data from a db for the requested parent category id. The data is then stored in an array and converted into JSON (Javascript Object Notation) format. This format is then used by JavaScript for populating tree view.
Categories : PHP, PHP Classes, Java Script, AJAX, Databases
Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented
Gonx URLs - This class is meant to generate URLs for accessing application dynamically generated pages based on parameters passed in the URL.
Categories : PHP, PHP Classes, Navigation, URLs
SPL and ITERATOR : examples
Categories : PHP, Object Oriented, PHP Classes, Sessions
TAB_STRUCT Class: Is supporting Class for the DBXML Class
Categories : PHP, PHP Classes, MySQL, XML, Databases
Menu in sliding bar or tree style. Handles frames by using small amount of javascript. Handles external and internal pages. Allows custom code to replace a menu item.
Categories : PHP Classes, PHP, Java Script, DHTML
pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes
XPertMailer - Sends TRUE Mails
Categories : PHP, Mail, SMTP, PHP Classes
PHP VXML Class : How to use PHP in VoiceXML applications
Categories : PHP, PHP Classes, VXML
Objects to XML Serializer/Unserializer
Categories : PHP, PHP Classes, DOM XML, Serialize
DbObject - A PHP wrapper for working with various databases
Categories : Databases, PHP, PHP Classes
Url To Pdf Report By Remote Application
Categories : PHP, PHP Classes, PDF, CURL
 Oswaldo Goite wrote :1900
Your code work PERFECT, I've tested it on a few browsers, 
such as Firefox 3.5.8, Safari 4.0.4, Opera 10.50, Chrome 
4.1.249.1036 and Internet Explorer 8. And It does what you 
say it does.


But, there's something You may be aware of, when I tried it 
in IE8, the text looks HUGE, it almost fills the screen 
from left to right... I don't know if that's an issue with 
your code or another stupidity from that browser... but... 
It's just for you to know it...


Thanks for that great code.


Cheers!