User Contributed Notes: get_browser
triad@df.lth.se
17-Dec-1999 05:47
get_browser() appears to be broken in PHP 4.0b2, I haven't verified b3 yet.
The most accurate browscap.ini database available is probably the one at: http://www.asptracker.com/
The PHP browscap.ini database seems to be non-existent or corrupt.
morten@coil.no
24-Jan-2000 03:27
Installed broscap.ini from 'http://www.cyscape.com/browscap/' - under PHP3. PHP now tells me that get_browser is an undefined function...
tstrum@salter.com
03-Feb-2000 12:31
morten: try puttign in the full path to the file... it looks like it's relative to php3.ini when you first edit it... I had the same thing happen, changed the file to the full path and it works fine now.
david.munsey-kano@dartmouth.edu
18-Feb-2000 01:37
I just tried installing browscap.ini from http://www.cyscape.com/browscap/ too
with php version 4 beta 3. I got a core dump when I restarted.
ledowong@netvigator.com
07-Mar-2000 03:08
I have no idea how to get it work ;(
I download and put the browscap.ini in the server, and edit the php.ini, enter the full path of the browscap.ini file.
I copy the php code in this page and try to run it, it show me:
<PRE>
Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)<hr>
<b>0:</b>
<PRE>
franz@e-trance.com
25-Mar-2000 06:20
can you set browscap to point to your browser.ini file if you don't have access to the php.ini file?
mog@linux.nu
30-Mar-2000 10:28
Seems pretty br0k3n in php-4.0b4pl1 too
marcel@celly.de
10-Apr-2000 06:44
Can I get the screen size, max. availible screen size a.s.o. with this function?
i_patton@hotmail.com
27-Apr-2000 09:31
Can somebody please explain the above example in something that works... or maybe something that the human brain can understand?
jeffrey@thompsonic.com
29-Apr-2000 07:43
get_browser() returns blank for me. I made sure and downloaded and installed the browscap.ini file and set it up in the php.ini file.
Hopefully get_browser() uses regular expressions based on browser type and version to set the information it returns, since it will be impossible to keep up with all the versions for all browsers.
Jeffrey Thompson
Thompson Internet Communications, Inc.
http://www.thompsonic.com
Marinne@ilovechocolate.com
01-May-2000 08:47
I just followed the steps found this manual, and it worked. For those people who had trouble making browscap work, here is what I've done on my system(I'm using PHP 3.0.14 on Windows98/PWS4.0)
1) Download browscap.zip on:
http://www.cyscape.com/browscap/
2) Unzip the file, copy browscap.ini as:
c:\WINDOWS\SYSTEM\inetsrv\browscap.ini
3) Edit this file:
c:\WINDOWS\php3.ini
Find the [browscap] section, and modify the path pointing to browscap.ini, i.e.:
browscap=c:\WINDOWS\SYSTEM\inetsrv\browscap.ini
Make sure the beginning ';' is removed.
4) Copy and paste the sample code on the manual, and it should work.
andysmith@post.com
06-May-2000 02:04
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:
<PRE>;
$ua = get_browser ();
if ( ( $ua->browser == "Netscape" ) && ( $ua->version < 5 ) ) {
// code to fix the page for netscape :)
}
</PRE>
olip@xzone.pl
09-May-2000 12:44
get_browser sux! if you wanna have simper way to determine which browser is it, use: "
$VER = intval(trim(substr($HTTP_USER_AGENT, 4 + strpos($HTTP_USER_AGENT, "MSIE"), 2)));
$IE = eregi("MSIE",$HTTP_USER_AGENT) && ($VER >= 4) == 1;"
epsilon7@asphyxia.com
12-May-2000 12:18
<pre>
Browser Detection Script, Ported from JavaScript
<a href=/old?u=http%3A%2F%2Fwww.php.net%2Fmanual%2F%26quot%3Bhttp%3A%2Fasphyxia.com%2FPHP_BD%2FbrowserDetector.phps%26quot%3B%26gt%3BSource%26lt%3B%2Fa%26gt&y=1999
<a href=/old?u=http%3A%2F%2Fwww.php.net%2Fmanual%2F%26quot%3Bhttp%3A%2Fasphyxia.com%2FPHP_BD%2F%26quot%3B%26gt%3BIn&y=1999 Action</a>
Returns:
Testing : Mozilla/4.73 [en] (Win98; U)
Browser : Netscape
Platform : Win98
Version : 4.73
Major Version : 4
Minor Version : 73
</pre>
epsilon7@asphyxia.com
12-May-2000 12:24
Just a note for above: browscap.ini is not needed. This script can probably be easily modified to report as much information as necessary. The code in pretty much uncommented, but a reference to the original JavaScript source is provided should you want to check it out.
hicking@du.gtn.com
15-May-2000 10:34
Make sure your browsercap file has proper linefeeds.
A version I download from http://www.cyscape.com was missing a linefeed on the last line which caused a segmentation fault in PHP 3.0.12 under Solaris : - (
hicking@du.gtn.com
15-May-2000 10:45
As of PHP 3.0.12 under Solaris you *cannot* put
php3_browscap /www/browscap.ini
in the apache configurationfile.
Instead, put it has to be in PHP3.INI
[browscap]
browscap = "/foo/bar/browscap.ini"
hicking@du.gtn.com
16-May-2000 03:31
PHP 3.0.15 is much more relaxed with the browscap.ini file. Still, if browscap is not present at apache start I get a segmentation fault.
And still you cannot put the browscap configuraion line in httpd.conf
(PHP 3.0.15 / Apache 1.3.12 / Solaris)
trio@surffi.net
08-Jul-2000 10:26
I followed the instructions to install browsercap but it dosenīt work right. Only feedback what the example gives:
Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
--------------------------------------------------------------------------------
0:
There is no errors in apacheīs error_log etc. What should I do? phpinfo-funtion gives browser.iniīs location right. PHP-version is 4 and I am using apache http-server.
Thanks!
stefan@digiconcept.net
13-Jul-2000 04:55
It's works (PHP 4.0.1pl2, Windows NT 4.0 build 1381,SVP 6)!!
Path in your ini-file is "browscap.ini", wich means the php-install-dir. I've got the browscap.ini-file from http://asptracker.com/, So there are some things to say: First you have to reaplace languageinformation throuh an asterix ($HTTP_USER_AGENT=eregi_replace("\[[a-z]{2,}\]", "*", $HTTP_USER_AGENT). Second: With this browser.cap, you will need to get the whole infos by your own.
example:
<pre>
$UA= getenv('HTTP_USER_AGENT');
$UA=eregi_replace("\[[a-z]{2,}\]", "*", $UA);
$array=get_Browser($UA);
while (list ($key, $value) = each ($array))
{
echo ("<b>$key:</b> $value \n");
}
$array=get_Browser('Netscape 4.0');
while (list ($key, $value) = each ($array))
{
echo ("<b>$key:</b> $value \n");
}
</pre>
:-)
abaddon@unwesen.com
16-Jul-2000 10:44
ok, it didn't work with my config (4.0.1pl2, file from asptracker)... so i coded this beauty (well, to be honest, it's quick'n'dirty):
http://www.unwesen.com/unwesen/pub/BrowseCaps.zip
it contains a class which does all the work and a mini script that uses the class... nowhere near elegant, but works well for me :)
have fun...
martin@nmso4.com
17-Jul-2000 03:05
Is there a way to check for the flash plugin??
triad@df.lth.se
30-Jul-2000 04:17
The only way browscap examines the target browser is through the HTTP_USER_AGENT so there is no way you can determine installed plug-ins. The only way to do that is through client-side JavaScripts.
dusty351@hotmail.com
10-Aug-2000 12:09
OK, I copied the script:
$ua = get_browser ();
if ( ( $ua->browser == "Netscape" ) && ( $ua->version < 5 ) ) {
// code to fix the page for netscape :)
}
but all I succeed in recieving is:
Warning: $ua is not an object in header.txt on line 9
where line 9 is the line with the if command. I am using php3. Any ideas?
vladislav_g@mail.ru
10-Aug-2000 11:56
Without get_browser () function:
if (strstr (getenv('HTTP_USER_AGENT'), 'Netscape')) {
// code
}