Home | Scripts | Tutorials | Books | Hosting | Forums | Links|

Navigation:

Home
Source code
Tutorials
RSS feeds
Articles
Wordpress plugins
Blog
Books
Software
Downloads
Hosting
manuals
Script directory
Training
Our Links






 
 

SPONSORS



 
 

Browser Detection

This example shows some simple browser detection . In this example we just display a message but in comments we have an example on how you would redirect your visitor to the browser specific page.

What we do is extract a certain part of the $HTTP_UER_AGENT info and then process the info . Here is a part of the browscap.ini .

[Mozilla/4.0 (compatible; MSIE 5.0; MSIECrawler; Windows NT)*]
parent=IE 5.0
platform=WinNT
crawler=True
version=5.01
minorver=#01

Most of this we are ignoring but the first line is important this is the line we are checking and for Internet Explorer we look for MSIE , here is a Netscape example

[Mozilla/4.5 * (Win95; I)]
parent=Netscape 4.0
platform=Win95
minorver=#5
version=4.5

So we will look for Mozilla., note this isnt fool proof as many browsers are based on Netscape or Internet Explorer .

Here is our script

<?php
$msie = eregi("MSIE" , $HTTP_USER_AGENT);
//look for MSIE in the HTTP_USER_AGENT
if ($msie == true)
{
echo ("You are using Internet explorer");
//header("location: internetexplorerpage.htm");
exit;
}
//now we will look for mozilla and of course if its not internet explorer
//we will assume its netscape navigator
$ns = eregi("mozilla" , $HTTP_USER_AGENT);
if ($ns == true)
{
echo ("You are using Netscape");
//header("location: netscapepage.htm");
exit;
}
//this is for all other browsers
else
{
echo ("You are not using Netscape or Internet explorer");
//header("location: otherpage.htm");
exit;
}
?>


And here are the results

You are not using Netscape or Internet explorer