I want to say
if (browser is internet explorer)
{
echo "true";
}
Can I do this with php? What's the actual code?
PHP Browser Detect
Moderator: General Moderators
Code: Select all
function get_browser_name( $user_agent ) {
$browsers = array( 'Opera' => 'Opera',
'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',
'SearchBot' => '(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp/cat)|(msnbot)|(ia_archiver)',
'Internet Explorer 6' => '(MSIE 6\.[0-9]+)',
'Internet Explorer 5' => '(MSIE 5\.[0-9]+)',
'Internet Explorer 4' => '(MSIE 4\.[0-9]+)',
);
foreach( $browsers as $browser => $pattern ) {
if ( eregi( $pattern, $user_agent ) )
return $browser;
}
return 'Unknown';
}Enjoy
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
It's the PHP Manual to the rescue!
$_SERVER['HTTP_USER_AGENT']
http://us2.php.net/manual/en/function.get-browser.php
$_SERVER['HTTP_USER_AGENT']
http://us2.php.net/manual/en/function.get-browser.php
It's been my experience that it's rarely configured... That's why the function.Note: In order for this to work, your browscap configuration setting in php.ini must point to the correct location of the browscap.ini file on your system.
See:
viewtopic.php?t=33819
I think the end of the thread has a link to the snippet posted above....
$_SERVER is an array of global predefined variables. One of them is 'HTTP_USER_AGENT'. It holds info about the person's browser. So refering to the function I posted earlier...
Untested...
Code: Select all
//Get the browser name
$browser = get_browser_name($_SERVER['HTTP_USER_AGENT']);
//Do a string comparison to see if it's IE
if(stristr('Internet Explorer', $browser)!==false){
//it's ie do something
} else{
//do nothing
}