Page 1 of 1

PHP version of navigator.appName

Posted: Wed Oct 29, 2003 5:24 pm
by d3ad1ysp0rk

Code: Select all

<script language="javascript">
var navName = navigator.appName;
document.write(navName);
</script>
gives you "Microsoft Internet Explorer" (example).

is there a PHP function that gives you just that (only the name, not the version, OS, or anything else)?

Thanks

Posted: Wed Oct 29, 2003 5:52 pm
by volka
if the client sents its USER_AGENT string with the request you can either read $_SERVER['HTTP_USER_AGENT'] or use get_browser(). The latter requires a proper browscap.ini as described at the manual page

But what's send within the USER_AGENT field is up to the client, either the value is correct, not set or something bogus.

Posted: Wed Oct 29, 2003 6:16 pm
by d3ad1ysp0rk
Found the solution i was looking for, thanks volka.

PHP.Net Comments:
andysmith at post dot com wrote: the example is great if you just want to spit out all that stuff, but i highly doubt anybody really wants to do that. To use the get_browser object in a conditional statement, do something like this:

Code: Select all

<?PHP 
$ua = get_browser (); 
if ( ( $ua->browser == "Netscape" ) && ( $ua->version < 5 ) ) { 
     // code to fix the page for netscape  
} 
?>

Posted: Wed Oct 29, 2003 6:19 pm
by d3ad1ysp0rk
Well.. not I get this:
Warning: get_browser(): browscap ini directive not set. in /home/des404/public_html/aim/subprofile.php on line 7
Is it in my code, or is it the server configuration?

Posted: Wed Oct 29, 2003 6:28 pm
by JAM
Short answer; server's php.ini.

Longer answer (from php.net);
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. browscap.ini is not bundled with PHP but you may find an up-to-date browscap.ini file here. http://www.garykeith.com/browsers/downloads.asp

By default, the browscap directive is commented out.

http://se.php.net/manual/en/ref.misc.php#ini.browscap