PHP Browser Detection for Conditional Firefox Banner
A few people have emailed me questions in response to my Slashdot post on conditionally promoting Firefox to Internet Explorer users who visit NewsCloud. So, here's a simple how to for other Web developers:
1. Sign up for an affiliate code at SpreadFirefox
2. Pick a banner that you like for the top of your site
3. NewsCloud is LAMP-based - so we use a derivative of this PHP browser detection class by Gary White.
4. When a visitor comes to your site with Internet Explorer, just put any HTML code you want at the top. The code can educate visitors about the problems with Internet Explorer and provide a link to upgrade to Firefox.
var $agent;
var $isIE=false;
$this->agent=$_SERVER['HTTP_USER_AGENT'];
$this->isIE=(eregi("msie",$this->agent) && !eregi("opera",$this->agent));
if ($this->isIE)
$addToHeader='<ol class="list"><a href="http://www.spreadfirefox.com/?q=affiliates&id=177807&t=197" target="_blank"><img style="border:0px;float:right;" alt="Upgrade to Firefox 1.5!" title="Upgrade to Firefox 1.5!" src="http://sfx-images.mozilla.org/affiliates/Buttons/120x60/safer.gif"/></a><a href="http://www.spreadfirefox.com/?q=affiliates&id=177807&t=55"><img style="border:0px;float:left;" alt="Get Firefox!" title="Get Firefox!" src="http://sfx-images.mozilla.org/affiliates/Buttons/180x60/trust.gif"/></a><b>Please consider upgrading your Web browser</b><p>Internet Explorer doesn\'t properly support CSS standards <a target="_blank" href="http://www.idealog.us/2006/08/analysis_of_int.html">(IE 52% vs. Firefox 93%)</a>. If you visit our site with Firefox or Safari, it works perfectly. NewsCloud recommends you upgrade to <a href="http://www.spreadfirefox.com/?q=affiliates&id=177807&t=191" target="_cts">Mozilla\'s open source Firefox browser</a> for a better experience with our Web site.</ol>';
Be sure to change the id= above to your own Spread Firefox affiliate - or give NewsCloud credit for the referral if you want to leave our ID in place.
We've also found this is useful for conditionally loading a small Internet Explorer-specific style sheet that fixes some of the problems with our column layouts. The css is still being tweaked.
if ($this->isIE)
$this->stylesheets[] = 'http://fairtrademedia.com/temp/ct/css/ie.css';
Hope this helps ... and good luck with spreading Firefox.
Technorati Tags: IE7, firefox, spread firefox, internet explorer, css, slashdot, css compliance, browser detection, php


why not just use microsoft's conditional statements to load ie specific stylesheets?
for example:
Posted by: ejay | Aug 19, 2008 at 06:29 PM