Page 1 of 2

Detect if user uses newest version of Firefox?

Posted: Sun May 14, 2006 1:11 pm
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.

Didn't notice that at first

Posted: Sun May 14, 2006 9:44 pm
by tr0gd0rr
Escape the brackets, i.e. "\["

Posted: Sun May 14, 2006 11:16 pm
by neoaddict
Wouldn't that cause it to be taken literally?

I want it to preg_match any number between 20060426-20061231.

Posted: Sun May 14, 2006 11:27 pm
by feyd
It won't be processed like that.

You may want to look at using get_browser() or a pure php version instead.

Posted: Mon May 15, 2006 9:44 am
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?

Posted: Tue May 16, 2006 1:33 pm
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

Posted: Tue May 16, 2006 2:10 pm
by feyd
quote your strings.

Posted: Tue May 16, 2006 5:22 pm
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.

Posted: Wed May 17, 2006 11:42 pm
by neoaddict
Bump.

Posted: Thu May 18, 2006 11:24 am
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

Posted: Thu May 18, 2006 7:41 pm
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]

?

Posted: Thu May 18, 2006 10:14 pm
by feyd
I've posted a pure php version of get_browser() previously.. :roll:

viewtopic.php?t=43988

Posted: Fri May 19, 2006 10:46 am
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{ }

?

Posted: Sat May 20, 2006 5:55 pm
by neoaddict
Am I an idiot to not know how to use the function? :(

Posted: Mon May 22, 2006 8:51 pm
by neoaddict
Sorry feyd, but could you give more of an explanation on how to use it?