PHP Magic Book – Free PHP Scripts, Tutorials and Downloads, PHP AtoZ Reloaded, free php tutorials, free php downloads, php scripts, PHP tips

Browser Check With PHP

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

  • Share/Bookmark
Tags: , , , , , ,
Posted in: Checks, Scripts
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0

Related Posts




One Response to “Browser Check With PHP”

  1. Oct 18, 2009
    tiong Says:

    nice little tips, thanks for sharing.

Post a Comment

  Subscribe Via RSS
  Subscribe Via Email