By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,274 Members | 2,229 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,274 IT Pros & Developers. It's quick & easy.

Mozilla vs Netscape and getenv("HTTP_USER_AGENT")

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
> 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.