Browser Check With PHP

by Hiroshi on August 4, 2008

in Checks, Scripts

Use this simple test for checking or detecting user’s browser information.

<?php
// browser test
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
   echo 'You are using Internet Explorer.<br />
   Get FireFox for better browsing.<br />';
}
else
{
echo 'You are <strong>NOT</strong> using Internet Explorer.<br />
Good for you.<br />';
}
?>
 
<?php
// for browser info
echo $_SERVER['HTTP_USER_AGENT'];
?>

Or simply.

<?php
// browser test
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{
?>
<div class="firefox">
Oyi...! Internet Explorer's dangerous... Get Firefox for safe and fast browsing... <a href="link">Click heya to get the FF</a>
</div>
<?
}
?>

You can put this css in head section of web page for warning message. And put above php script at the top of all your web page content.

<style type="text/css">
<!--
.firefox {
	font: 11px Verdana, Arial, Helvetica, sans-serif;
	color: #666666;
	text-decoration: none;
	background: #f8eada;
	display: block;
	padding: 2px;
	width: 100%;
	overflow: visible;
	position: fixed;
	visibility: visible;
	text-align: center;
	margin-bottom: 10px;
	vertical-align: middle;
	border-bottom: 1px solid #f2d9bd;
}
body {
	margin: 0px;
	padding: 0px;
	font: 11px Verdana, Arial, Helvetica, sans-serif;
	color: #666666;
	text-decoration: none;
}
.firefox a {
	font: 11px Verdana, Arial, Helvetica, sans-serif;
	color: #ff6600;
	text-decoration: none;
}
.firefox a:hover {
	font: 11px Verdana, Arial, Helvetica, sans-serif;
	color: #000000;
	text-decoration: none;
}
-->
</style>

Download Browser Test Example

Related Posts

Previous post:

Next post: