WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 7 times)
Viewed : 10443
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  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
Blueshoes PHP Application Framework
Categories : PHP, Frameworks, PHP Classes
How To Create a PDF Using PHP
Categories : PHP, PDF, PHP Classes, HTML and PHP
Banknote Validation - A PHP class that provides several methods to quickly validate banknote serial numbers of the following currencies: AUD, CAD, CHF, CNY, EUR, GBP, JPY, USD.
Categories : PHP, PHP Classes, Data Validation, Regexps
Class to convert any document, that can be read by MS Word, to another format supported by Word.
Categories : PHP Classes, PHP, Windows 2000, Microsoft Word, WinNT
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
Scramble Eggs - php class to scramble/encode
Categories : PHP, PHP Classes, Security, Encryption
.htpassword manager for apache
Categories : PHP, PHP Classes, Authentication, Apache
Freshmeat.net XML-RPC - This class is meant to query Freshmeat for information about registered projects.
Categories : PHP, PHP Classes, XML, Web Services
Directory Listing To XML : Outputs XML File of a Given Directory Listing
Categories : PHP, PHP Classes, XML, Directories
My Box - PHP Class that calculates the volumetric weight of a package.
Categories : PHP, Object Oriented, PHP Classes, Beginner Guides, Payment Gateways
These PHP Classes Check if a host is alive using various methods.
Categories : PHP, PHP Classes, Sockets, CURL
Sample usage of IPv6 and IPv4 with PHP
Categories : PHP, PHP Classes, Network
[PHP5] PHP Debugger and Helper
Categories : PHP, PHP Classes, Errors and Logging, Debugging, XML
 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!