Page 1 of 1

Detect Gecko Version (not build) working JS provided! :-)

Posted: Wed Jan 25, 2006 1:12 pm
by JAB Creations
What the provided JavaScript does is exactly what I want to do only I want to do it in PHP! Only one extra step, I want to assign $gecko to whatever version the Gecko engine is (to deal with Gecko bugs that have lingered longer then insert something wity here).

For example, Firefox 1.5's UA is...
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5
So if we printed out the variable we'd get...
1.8
But I simply have no clue how to do this in PHP!

Anyway here is the working JavaScript.
<script type="text/javascript">
<!--
var str = navigator.userAgent;
/***
/^rv\:|\).*$/g
***/
var gecko = str.replace(/^Mozilla.*rv:|\).*$/g, '' ) || ( /^rv\:|\).*$/g, '' );
document.writeln(gecko);
var version = gecko.substring(0,3);
if (version == 1.6) {document.writeln('<br />1.6')}
else if (version == 1.7) {document.writeln('<br />1.7')}
else if (version == 1.8) {document.writeln('<br />1.8')}
else if (version == 1.9) {document.writeln('<br />1.9')}
else {document.writeln('<br />Unknown Gecko code')};
//-->
</script>
John

Posted: Wed Jan 25, 2006 1:16 pm
by Roja

Posted: Wed Jan 25, 2006 1:22 pm
by JAB Creations
Thanks! :D

Posted: Wed Jan 25, 2006 1:34 pm
by JAB Creations
I'm a little in the dark about how to pull the info from this...

How can I echo gecko_ver?

Posted: Wed Jan 25, 2006 1:39 pm
by Roja
JAB Creations wrote:I'm a little in the dark about how to pull the info from this...

How can I echo gecko_ver?

Code: Select all

echo $client->property('gecko_ver');

Posted: Wed Jan 25, 2006 1:49 pm
by JAB Creations
Now there is an error of some type, thanks for sticking on this with me! :D

I got an error and decided to add the line you suggested to the bottom of the script itself and the same error came up for...
print $client->property('gecko_ver');
The error was...
Call to a member function property() on a non-object in sniff.php on line 907
John