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

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
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

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

Post 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
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Post by JAB Creations »

Thanks! :D
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Post by JAB Creations »

I'm a little in the dark about how to pull the info from this...

How can I echo gecko_ver?
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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');
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

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