bobleny Posted July 5, 2006 Share Posted July 5, 2006 How can I detect a users browser type and version? (e.g. Internet Explorer 6.2) Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/ Share on other sites More sharing options...
birdie Posted July 5, 2006 Share Posted July 5, 2006 All info like that are stored in the $_SERVER variable.$_SERVER[HTTP_USER_AGENT] == users browser Hope that helped ;D Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-53601 Share on other sites More sharing options...
bobleny Posted July 5, 2006 Author Share Posted July 5, 2006 Neat, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4".But how do I create an if statment out of it? I wan't to use this to limit the abilitys of IE. Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-53607 Share on other sites More sharing options...
nogray Posted July 5, 2006 Share Posted July 5, 2006 There is a [url=http://us2.php.net/manual/en/function.get-browser.php]get_browser()[/url] function in phpJust look it up in php.net Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-53610 Share on other sites More sharing options...
bobleny Posted July 5, 2006 Author Share Posted July 5, 2006 I just keep getting error messages with the get_browser() function! I tried the examples there at php.net. Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-53615 Share on other sites More sharing options...
nogray Posted July 6, 2006 Share Posted July 6, 2006 I am not sure if you notice this part[quote]Note: In order for this to work, your [url=http://us2.php.net/manual/en/ref.misc.php#ini.browscap]browscap[/url] 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 [url=http://browsers.garykeith.com/downloads.asp]up-to-date php_browscap.ini[/url] file here.[/quote]if the get_browser() doesn't work on your server, you can use an alternative at http://alexandre.alapetite.net/doc-alex/php-local-browscap/ Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-53636 Share on other sites More sharing options...
bobleny Posted July 6, 2006 Author Share Posted July 6, 2006 lol, yes, I did miss that. I went through it again 3 other times before I seen it. Anyways, it seems to me as though it is the same as $_SERVER[HTTP_USER_AGENT]. Is it not? Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-53656 Share on other sites More sharing options...
toplay Posted July 6, 2006 Share Posted July 6, 2006 FYI:http://techpatterns.com/downloads/php_browser_detection.php#php_fullhttp://www.apptools.com/phptools/browser/http://www.sitepoint.com/article/browsers-suck-php-rescuehttp://www.phpclasses.org/browse/package/2669.html Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-53662 Share on other sites More sharing options...
nogray Posted July 6, 2006 Share Posted July 6, 2006 [quote]it seems to me as though it is the same as $_SERVER[HTTP_USER_AGENT]. Is it not?[/quote]It uses the $_SERVER[HTTP_USER_AGENT] to get the browser info, but it also uses a database to fill in all the details, Here is a sample output[quote]Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3Array( [browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$ [browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9* [parent] => Firefox 0.9 [platform] => WinXP [browser] => Firefox [version] => 0.9 [majorver] => 0 [minorver] => 9 [css] => 2 [frames] => 1 [iframes] => 1 [tables] => 1 [cookies] => 1 [backgroundsounds] => [vbscript] => [javascript] => 1 [javaapplets] => 1 [activexcontrols] => [cdf] => [aol] => [beta] => 1 [win16] => [crawler] => [stripper] => [wap] => [netclr] => )[/quote]as you can see, you'll get all the browser details such as the name, version, support for css, frames, javascript, java, etc etc.... (the support part is if the browser is capable, and not if the user have it turned on or off). Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-54035 Share on other sites More sharing options...
bobleny Posted July 9, 2006 Author Share Posted July 9, 2006 Yeah, but that is over kill and unnecessary. All I require is the browser type (Firefox) and the browser version (1.5.0.4).I now know how to get it ($_SERVER[HTTP_USER_AGENT]). This is what I get in my FF, “Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4.” How do I only pull out parts of this code?Insight:I need this to determine the level of accesses the user is given based upon the browsers capability to display semi-transparent ping images.More insight:I am in the process of re-scripting my site with the feature of themes. This way the user has the ability to choose a theme and with that theme there will be new colors, new background, and new photos. Unfortunately, not all browsers have the ability to support the semi-transparency of ping images. This is not my concern, my concern is how to nitpick the response from the $_SERVER[] code. Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-55013 Share on other sites More sharing options...
Daniel0 Posted July 9, 2006 Share Posted July 9, 2006 [code]$browser = get_browser(null, true);$browser = $browser['parent'];[/code]This would get the browser name and version (i.e. Firefox 1.5). Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-55033 Share on other sites More sharing options...
bobleny Posted July 9, 2006 Author Share Posted July 9, 2006 In my php.ini file (located at C:\wamp\Apache2\bin), this is the only thing about the browscap.ini[browscap];browscap = extra/browscap.iniI put my browscap.ini file in C:\wamp\Apache2\bin\extraand used this script:<?php $_SERVER['HTTP_USER_AGENT']; $browser = get_browser(null, true); $browser = $browser['parent']; echo $browser; ?>this is the error message I always get:Warning: get_browser() [function.get-browser]: browscap ini directive not set. in C:\wamp\www\Tests\alignment.php on line 1What am I doing wrong? Why isnt it working? Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-55232 Share on other sites More sharing options...
kenrbnsn Posted July 9, 2006 Share Posted July 9, 2006 Did you restart the Apache webserver after you modified the php.ini file?Ken Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-55233 Share on other sites More sharing options...
bobleny Posted July 9, 2006 Author Share Posted July 9, 2006 Actually I didnt modify the php.ini file. It already had:[browscap];browscap = extra/browscap.iniI just created the folder "extra" and placed my browscap.ini file in it. Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-55235 Share on other sites More sharing options...
kenrbnsn Posted July 9, 2006 Share Posted July 9, 2006 You need to remove the initial semi-colon from the beginning of that line, since that makes it into a comment. Save the file and restart Apache.Ken Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-55236 Share on other sites More sharing options...
Daniel0 Posted July 9, 2006 Share Posted July 9, 2006 And after doing that you can delete the browscap.ini file in your directory (it's not being used). Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-55240 Share on other sites More sharing options...
bobleny Posted July 9, 2006 Author Share Posted July 9, 2006 Thanks, I no longer have the error message. However, I don't have any message.This is the browscap file that I am useing (it was to big to post it):http://browsers.garykeith.com/stream.asp?PHP_BrowsCapINIIt says it is a special browscap file and maybe thats why it doesnt show anything when I use:<?php $_SERVER['HTTP_USER_AGENT']; $browser = get_browser(null, true); $browser = $browser['parent']; echo $browser; ?>So how do I make this work? Maybe I just need a normal browscap.ini file but I cant find one... Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-55257 Share on other sites More sharing options...
bobleny Posted July 10, 2006 Author Share Posted July 10, 2006 Bumpady Upady Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-55561 Share on other sites More sharing options...
Daniel0 Posted July 10, 2006 Share Posted July 10, 2006 1. Did you rename it from php_browscap.ini to browscap.ini?2. Where did you put it? Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-55573 Share on other sites More sharing options...
bobleny Posted July 10, 2006 Author Share Posted July 10, 2006 [quote author=Daniel0 link=topic=99583.msg394449#msg394449 date=1152542617]1. Did you rename it from php_browscap.ini to browscap.ini?2. Where did you put it?[/quote]1.)Yes, I have renamed the file to browscap.ini2.) I placed it in, "C:\wamp\Apache2\bin\extra". I have placed it in this file because the php.ini file points to, "[browscap] browscap = extra/browscap.ini" Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-55913 Share on other sites More sharing options...
bobleny Posted July 11, 2006 Author Share Posted July 11, 2006 I found another browscap.ini file. In the process of changing the files, I decided to try the code with out the browscap file and my results where the same, no errors or words. So something’s wrong here, and it’s probably my fault. Can’t any one help? Quote Link to comment https://forums.phpfreaks.com/topic/13791-detecting-a-users-browser-with-php/#findComment-55956 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.