How do I get the browser version? I have done the browser detection part but every browser have different algorithm of its version release and its hard to get it. I already have looked in PHP's manual about get-browser function but every script seems out of my brain.
Asked
Active
Viewed 2,461 times
0
-
Why do you want to determine the browser's version? – Bart Nov 01 '11 at 13:17
-
2Out of curiousity: Why do you want to? Is there some reason you need to know? If it's so you know what it can do, that's usually a bad idea; instead, use **feature detection**. Some useful ones [here](http://kangax.github.com/cft/) and [here](http://www.modernizr.com/). This future-proofs your code and makes it so you don't have to constantly update it as browser versions change. – T.J. Crowder Nov 01 '11 at 13:18
-
I am making my own page which tells my system's detail. – Santosh Kumar Nov 01 '11 at 13:21
-
possible duplicate of [Any php code to detect the browser with version and operating system?](http://stackoverflow.com/questions/2142030/any-php-code-to-detect-the-browser-with-version-and-operating-system) – CharlesB Nov 02 '11 at 08:32
4 Answers
3
You can get it easily with get_browser()
<?php
$browser = get_browser();
$version = $browser->version;

genesis
- 50,477
- 20
- 96
- 125
-
This community is for advanced user I think, this give an error like this **Fatal error: Cannot use object of type stdClass as array in D:\xampp\htdocs\new.php on line 3** – Santosh Kumar Nov 01 '11 at 13:29
-
-
0? it is returning zero when echoing **$version** while I'm using Google Chrome 14.0.835.202 – Santosh Kumar Nov 01 '11 at 13:38
-
Ok, I have browsercap.ini file up and running but i still get version 0 – Santosh Kumar Nov 01 '11 at 14:29
-
@Santosh if problem still unsolved you can ask another question posting the content of `$browser` – CharlesB Nov 02 '11 at 08:54
2
Your only chance is to grab the User-Agent
from the $_SERVER
array. And there is no rule that forces a browser to include its version.

Till Helge
- 9,253
- 2
- 40
- 56
2
A google search for 'php browser version detection' return get_browser() as the first result. Please search before posting.

Whetstone
- 1,199
- 8
- 8
0
I have found PPK's JavaScript-based browser detection code to be very reliable.

mvark
- 2,105
- 2
- 21
- 36