Synkc
Active Member
- Messages
- 1,765
- Reaction score
- 0
- Points
- 36
This is a quick an easy script which will show an “Incompatible Browser Detected” message to any end-user while they are using Internet Explorer. They will then have the option of downloading Firefox, or to continue browsing your site with Internet Explorer. You can also make money out of this with Google referrals ($1 per referral).
How to use it
You could use either a php include, or require function to include the code into each of your site pages, or place this code within a global.php, or config.php file, which all your site pages have access to. The code must be placed before any html output to the end user is declared; otherwise the script will throw an error; this is an requirement of the setcookie() function.
How it works
First off, this script will check whether the end-user has not received the cookie “IgnoreFirefox”; if they have, the rest of the code is not executed, and the user is free to view your site; otherwise, the script will send the incompatible browser notification, and sets the cookie. As such, users with Internet Explorer will need to allow cookies for your site; otherwise they will never be able to bypass this page.
The browser detection is calculated with the code:
It works by performing a search for the first occurrence of the keyword “msie” in the $_SERVER["HTTP_USER_AGENT"] array, and if the result returns true, they are using Microsoft Internet Explorer, and the “if” statement also returns true.
You may ask, why am I using two “if” statements, instead of using an “and” operator to fuse the two together. Well this way, fewer resources will be extinguished by users using any browser other then IE; none of the code will be executed since the first if statement will return false (you don’t need to store a cookie on their machine if they are not using IE.
Finally, the code:
Will send the actual cookie to the browser; as we are only checking whether the cookie does not exist, giving it a value is not necessary. The time() function determines the length of time the cookie remains valid for; passing the time specified (604800 seconds) will result in the cookie begin destroyed, and the user will be prompted with the message again. The default time is set to one week.
If you have any questions, feel free to ask.
And I love suggestions and feedback.
PHP:
if (stristr($_SERVER["HTTP_USER_AGENT"], "msie")){
if (!isset($_COOKIE["IgnoreFirefox"])) {
setcookie("IgnoreFirefox", time()+604800);
echo"<div style=\"background:#e8fafe;border:#00586b 2px solid;padding:5px\">
<span style=\"font-weight:bold;text-decoration:underline;font-size:25px\">Incompatible Browser Detected</span><br /><br />
You are currently using Microsoft Internet Explorer, which is not fully compatible with this site.<br />
It is recommended that you upgrade to a more W3C compilable web browser, such as <a style=\"text-decoration:none\" href=\"http://en.wikipedia.org/wiki/Firefox\">Mozilla Firefox</a>, the preferred browser for viewing this website.
Firefox may be downloaded for free from <a style=\"text-decoration:none\" href=\"http://firefox.com\">http://firefox.com</a>.<br /><br />
You may continue browsing this site with Internet Explorer, however, you may experience issues regarding the display and rendering of page content.<br /><br />
If you are experiencing issues bypassing this page, make sure that Cookies are enabled for this site.<br /><br /><br />
<a style=\"text-decoration:none\" href=\""."http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]."\">Continue without Firefox »</a>
</div>";
exit;
}
}
How to use it
You could use either a php include, or require function to include the code into each of your site pages, or place this code within a global.php, or config.php file, which all your site pages have access to. The code must be placed before any html output to the end user is declared; otherwise the script will throw an error; this is an requirement of the setcookie() function.
How it works
First off, this script will check whether the end-user has not received the cookie “IgnoreFirefox”; if they have, the rest of the code is not executed, and the user is free to view your site; otherwise, the script will send the incompatible browser notification, and sets the cookie. As such, users with Internet Explorer will need to allow cookies for your site; otherwise they will never be able to bypass this page.
The browser detection is calculated with the code:
PHP:
stristr($_SERVER["HTTP_USER_AGENT"], "msie")
It works by performing a search for the first occurrence of the keyword “msie” in the $_SERVER["HTTP_USER_AGENT"] array, and if the result returns true, they are using Microsoft Internet Explorer, and the “if” statement also returns true.
You may ask, why am I using two “if” statements, instead of using an “and” operator to fuse the two together. Well this way, fewer resources will be extinguished by users using any browser other then IE; none of the code will be executed since the first if statement will return false (you don’t need to store a cookie on their machine if they are not using IE.
Finally, the code:
PHP:
setcookie("IgnoreFirefox", time()+604800);
If you have any questions, feel free to ask.
And I love suggestions and feedback.
Last edited: