471,354 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Mozilla vs Netscape and getenv("HTTP_USER_AGENT")

Hi,

if i use...

// php
$info = getenv("HTTP_USER_AGENT");
// I noticed that Mozzila and Netscape <6(?) both use the same Agent.
// so i was thinking of

if (preg_match("/Mozilla/i", $info)) {
if (preg_match("/rv:/i", $info)) { $web = "Mozilla"; }
else
if (preg_match("/Mozilla\/3/i", $info)) { $web = "Netscape 3.x"; }
else
if (preg_match("/Mozilla\/4.5/i", $info)) { $web = "Netscape 4.5"; }
else
if (preg_match("/Mozilla\/4.6/i", $info)) { $web = "Netscape 4.6"; }
else
if (preg_match("/Mozilla\/4.7/i", $info)) { $web = "Netscape 4.7"; }
else
if (preg_match("/Mozilla\/4/i", $info)) { $web = "Netscape 4.x"; }
else
{ $web = "Mozilla"; }
}

Is the code above correct or is there a better way of doing it?
Regards

Sims
Jul 17 '05 #1
1 4917
> Hi,

if i use...

// php
$info = getenv("HTTP_USER_AGENT");
// I noticed that Mozzila and Netscape <6(?) both use the same Agent.
// so i was thinking of


Ok, after playing around i think i have refined it to

// php
$info = getenv("HTTP_USER_AGENT");

if (preg_match("/Mozilla/i", $info))
{
if (preg_match("/Mozilla\/3/i", $info)) { $web = "Netscape 3.x"; }
else if (preg_match("/Mozilla\/4.5/i", $info)) { $web = "Netscape
4.5"; }
else if (preg_match("/Mozilla\/4.6/i", $info)) { $web = "Netscape
4.6"; }
else if (preg_match("/Mozilla\/4.7/i", $info)) { $web = "Netscape
4.7"; }
else if (preg_match("/Mozilla\/4/i", $info)) { $web = "Netscape
4.x"; }
else if (preg_match("/Netscape\/6/i", $info)) { $web = "Netscape
6"; }
else if (preg_match("/Netscape\/7/i", $info)) { $web = "Netscape
7"; }
else { $web = "Mozilla"; }
}

Regards

Sims
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.