[PHP] Prompt IE Users + Make Money

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).

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 &raquo;</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);
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. :p
 
Last edited:

GG-Xtreme

New Member
Messages
430
Reaction score
0
Points
0
I had something like this written in JavaScript a while ago, but too many people complained.
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Since this only appears once per 24 hours, I suppose it wouldn't be too much of an irritant =)

I've got something similar on my new upcoming site
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
You should also do a sessions check just in case cookies are disabled they will see the message over and over again.

Sessions won't get rid of the message but at the very least, you will only see them once per session. A more intensive way would be to store the IPs and time of last visit :D
 

Sharky

Community Paragon
Community Support
Messages
4,399
Reaction score
94
Points
48
Only problem there is that the majority of sites aren't "not fully compatible" (double negative I know...), so it's just gimmicky rubbish.

Kudos on knowing how to make this sort of thing though ;P
 
Top