Jump to content

[SOLVED] Distingush between browsers Users are visiting your page with.


Wildhalf

Recommended Posts

Hi all,

 

This is an easy one for some of you but i haven't seen a way to do it...

 

I want to distingush between browsers Users are visiting your page with. If there using anything other than IE i want to tell them that the page is best view in IE and try get them to open it in IE.

 

Anyone have any ideas???

you can see what browser a user is using like this:

 

echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

 

Im not sure if there is function to distinguish between browsers but ince you have got the data you could always use preg_match() if it finds a match then output your page if not display the message.

Just found this on the web. 

 

if (!empty($_SERVER['HTTP_USER_AGENT'])) 
{ 
   $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT']; 
} 
else if (!empty($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) 
{ 
   $HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT']; 
} 
else if (!isset($HTTP_USER_AGENT)) 
{ 
   $HTTP_USER_AGENT = ''; 
} 
if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) 
{ 
   $browser_version = $log_version[2]; 
   $browser_agent = 'opera'; 
} 
else if (ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) 
{ 
   $browser_version = $log_version[1]; 
   $browser_agent = 'ie'; 
} 
else if (ereg('OmniWeb/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) 
{ 
   $browser_version = $log_version[1]; 
   $browser_agent = 'omniweb'; 
} 
else if (ereg('Netscape([0-9]{1})', $HTTP_USER_AGENT, $log_version)) 
{ 
   $browser_version = $log_version[1]; 
   $browser_agent = 'netscape'; 
} 
else if (ereg('Mozilla/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) 
{ 
   $browser_version = $log_version[1]; 
   $browser_agent = 'mozilla'; 
} 
else if (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) 
{ 
   $browser_version = $log_version[1]; 
   $browser_agent = 'konqueror'; 
} 
else 
{ 
   $browser_version = 0; 
   $browser_agent = 'other'; 
}
echo '<HR WIDTH="100%" COLOR="black"/>';
print '<B>Browser Type:</B> ' . $browser_agent; 
echo '<BR />';
print '<B>Browser Version #:</B> ' . $browser_version;
echo '<HR WIDTH="100%" COLOR="black"/><PRE><B>Full Details:</B> ';
print_r( $HTTP_USER_AGENT );
echo '</PRE><HR WIDTH="100%" COLOR="black"/>';

 

Give all the credit to this site.....Site

Remember that things like:

 

$_SERVER['HTTP_REFERER']

$_SERVER['HTTP_USER_AGENT']

 

are set by the user agent it self (the browser) and it can therefore be manipulated. I guess some browsers even offer the ability to do that very easy. But of course if it's for the viewers own good you can give a heck about someone trying to cheat it / bypass it - since it will only do them no good :)

Works perfectly... Thanks again

 

Just found this on the web. 

 

if (!empty($_SERVER['HTTP_USER_AGENT'])) 
{ 
   $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT']; 
} 
else if (!empty($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) 
{ 
   $HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT']; 
} 
else if (!isset($HTTP_USER_AGENT)) 
{ 
   $HTTP_USER_AGENT = ''; 
} 
if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) 
{ 
   $browser_version = $log_version[2]; 
   $browser_agent = 'opera'; 
} 
else if (ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) 
{ 
   $browser_version = $log_version[1]; 
   $browser_agent = 'ie'; 
} 
else if (ereg('OmniWeb/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) 
{ 
   $browser_version = $log_version[1]; 
   $browser_agent = 'omniweb'; 
} 
else if (ereg('Netscape([0-9]{1})', $HTTP_USER_AGENT, $log_version)) 
{ 
   $browser_version = $log_version[1]; 
   $browser_agent = 'netscape'; 
} 
else if (ereg('Mozilla/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) 
{ 
   $browser_version = $log_version[1]; 
   $browser_agent = 'mozilla'; 
} 
else if (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) 
{ 
   $browser_version = $log_version[1]; 
   $browser_agent = 'konqueror'; 
} 
else 
{ 
   $browser_version = 0; 
   $browser_agent = 'other'; 
}
echo '<HR WIDTH="100%" COLOR="black"/>';
print '<B>Browser Type:</B> ' . $browser_agent; 
echo '<BR />';
print '<B>Browser Version #:</B> ' . $browser_version;
echo '<HR WIDTH="100%" COLOR="black"/><PRE><B>Full Details:</B> ';
print_r( $HTTP_USER_AGENT );
echo '</PRE><HR WIDTH="100%" COLOR="black"/>';

 

Give all the credit to this site.....Site

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.