PHP version of navigator.appName

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

PHP version of navigator.appName

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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  
} 
?>
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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
Post Reply