Detect if user uses newest version of Firefox?

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Detect if user uses newest version of Firefox?

Post by neoaddict »

Code: Select all

<?php
$uab = $_SERVER["HTTP_USER_AGENT"];

if (preg_match("#Mozilla\/5\\.0 (.*) Gecko\/[20060426-20061231] Mozilla Firefox|BonEcho|Minefield\/(.*)#i", $uab, $match)){
echo "Your browser is up to date!";
echo $match[0];
}
else{
echo "Negative";
}
?>
I'm trying to use a code to see if the browser the user uses is the latest version of Firefox or a beta version but it keeps on giving me this error:

Warning: preg_match(): Compilation failed: range out of order in character class at offset 36 in [PATH] on line 68
Negative

Any help would be appreciated.
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Didn't notice that at first

Post by tr0gd0rr »

Escape the brackets, i.e. "\["
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

Wouldn't that cause it to be taken literally?

I want it to preg_match any number between 20060426-20061231.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It won't be processed like that.

You may want to look at using get_browser() or a pure php version instead.
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

So something like:

Code: Select all

<?php
$ua = $_SERVER['HTTP_USER_AGENT'];

$browser = get_browser(null, true);

if (($browser[browser] == Firefox) || ($browser[browser] == Minefield) || ($browser[browser] == BonEcho) && ($browser[version] >= 1.5.0.3) && ($ua, stristr != Opera)){ 
echo "You're using the most updated version of Firefox/Minefield/BonEcho!";
}
else{
echo "Please upgrade your browser.";
}
Am I right or no?
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

Current code:

Code: Select all

<?php
$ua = $_SERVER['HTTP_USER_AGENT'];

$browser = get_browser(null, true);

if (($browser[browser] == Firefox) || ($browser[browser] == Minefield) || ($browser[browser] == BonEcho) && ($browser[version] >= 1.5.0.3) && (!stristr($ua, "Opera")){
echo "You're using the most updated version of Firefox/Minefield/BonEcho!";
}
else{
echo "Please upgrade your browser.";
}
?>
Now I'm getting this error:

Parse error: syntax error, unexpected T_DNUMBER in [PATH] on line 70

Thanks. :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

quote your strings.
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

I put quotes around the browser names and version number, and I got a parse error for unexpected {.

Then I put quotes only around the version number and I think I got either the parse error again or the DNUMBER error.
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

Bump.
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

neoaddict wrote:I put quotes around the browser names and version number, and I got a parse error for unexpected {.

Then I put quotes only around the version number and I think I got either the parse error again or the DNUMBER error.
Watch your braces ;)

Code: Select all

<?php
$ua = $_SERVER['HTTP_USER_AGENT'];

$browser = get_browser(null, true);

if ((($browser[browser] == "Firefox") || ($browser[browser] == "Minefield") || ($browser[browser] == "BonEcho")) && ($browser[version] >= "1.5.0.3") && (!stristr($ua, "Opera"))){
echo "You're using the most updated version of Firefox/Minefield/BonEcho!";
}
else{
echo "Please upgrade your browser.";
}
?>
aerodromoi
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

Oh, just my luck. Host doesn't support browscap.ini.

Anyways, how would I get preg_match to identify Gecko IDs?

[20060426-20061231]

?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I've posted a pure php version of get_browser() previously.. :roll:

viewtopic.php?t=43988
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

It's good, but how do you well, use it to find a browser name?

eg. if (feyd_get_browser[browser] == "Firefox"){ }else{ }

?
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

Am I an idiot to not know how to use the function? :(
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

Sorry feyd, but could you give more of an explanation on how to use it?
Post Reply