"If Not IE6" PHP Statement

Hello,
I currently have this code on my site which works great for redirecting IE6 users:

<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.0') !== TRUE) {
header("Location: http://www.yourwebsiteurl.com/");
}?>

But I would like to get the opposite running now, to redirect users that are not running IE6. I tried switching “!==TRUE” to “!==FALSE” but it didn’t work.
Any ideas?

Thanks in advance!

Anyone using almost any browser might have the useragent set to identify their browser like that - the useragent field is a free format one that can be set to anything in many browsers. What do you do if someone has their IE6 set to identify itself as Firefox 4?

The only guaranteed way to detect IE 6 is using Microsoft conditional comments in the HTML.

OK, thanks Felgall.
I didn’t know you could set IE6 to identify itself as Firefox 4. Good to know!

I can change the PHP “if IE6” statement to use HTML comments. The reason I like PHP is that it doesn’t show the code in the markup (when I click view source). Is it possible to put HTML comments inside of something like a JavaScript file to help clean up the source code?

I will look into the HTML comments method to find the proper fix for “if IE6”.
But the method I’m really looking for is “if not IE6”… will HTML comments work for all of the browsers or am I better off with using PHP?

Thanks!

You can do a conditional HTML comment for IE6, and the content would be JavaScript redirecting to [upgradeOrDiePlease].com

See the source of my website (signature) to see how I’ve done it.

There is a JScript equivalent conditional comment where you can test what version of JScript that IE is running. That doesn’t necessarily relate to a specific version of IE though as Microsoft sometimes update JScript independently of IE. Usually IE7 and later will be running JScript 5.7 or later while IE6 and earlier will be running an earlier JScript version.

/*@cc_on
  @if (@_jscript)
alert('This browser is running JScript - that is it is Internet Explorer');
  @if (@_jscript_version >= 5.7)
alert('JScript version is 5.7 or greater so is probably IE7 or later');
  @end
  @else */
alert('This browser is running JavaScript so it is not IE');   /*
  @end
@*/

Thanks for the help. I found the code you are referencing to here, AlienDev:
http://coronatus.com/js/main.js
And checking the JScript version seems like an interesting method but not guaranteed either.

Upon further review, I think I’m gonna stick to the PHP method I am currently using and posted about to begin with…
How many users actually use IE6 in “Firefox mode”? I honestly can’t see it being very many…

Basically I would just like to know how to modify this PHP code

<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.0') !== TRUE) {
header("Location: http://www.yourwebsiteurl.com/");
}?>

to be “if not IE6”… Hoping it’s an easy fix.

Thanks for all of your help and suggestions so far.
Warmest Regards,

strpos returns an integer or false, so it would always !== true


if(strpos($string, $substring) === false) {
    // $substring is not in $string
}
else {
    // $substring is in $string
}

<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.0') == false) {
header("Location: http://www.yourwebsiteurl.com/");
}?>

See if that works for you.

As for users not displaying IE6 as Firefox 4 - you’re right. Anyone who knows how to set IE6 to display as something else, likely won’t be using IE6 anyway.

Hey ferrari_chris,
Thanks for the code! I tested it out and got this:

Warning: Cannot modify header information - headers already sent by (output started at /home/revlimit/public_html/upgrade/index.php:7) in /home/revlimit/public_html/upgrade/index.php on line 15

I’m not too good with PHP. This error doesn’t show up in IE6 but it does in IE7, IE8, Opera 10, Safari 4, Chrome and Firefox 3.6
Do you know what could be causing this error?
Thanks!

[QUOTE=ferrari_chris;4536013As for users not displaying IE6 as Firefox 4 - you’re right. Anyone who knows how to set IE6 to display as something else, likely won’t be using IE6 anyway.[/QUOTE]

Yes it is far more likely the other way around with lots of Firefox, Opera, Safari etc users having their browser set to report itself as IE6 to get around problems with older web pages that will not let you use the page if your browser isn’t IE6.

Both IE and Firefox allow the useragent to be set to anything at all while Opera, Safari etc allow you to choose to set the useragent to identify as a version of IE or Firefox (which version it will report as depends on the browser version you start with).

In the case of Opera the useragent can also be changed by the people at Opera instructing the browser to automatically switch to using an IE or Firefox useragent for specific pages and then even the person using the browser has no idea what useragent is being used for a particular web site.

Basically checking Microsoft HTML conditionals is 100% accurate. Checking JScript conditionals will positively identify IE but may not get the version right all the time. Checking the useragent is not going to be accurate for any browser 100% of the time since even the person using the browser will not necessarily know if the people who wrote the browser have implemented dynamic switching so as to always report as a different browser for a given web site.

It is quite interesting if you visit certain web pages using any version of IE or Firefox with the useragent set to the one used by the googlebot.

Hmmm, so many possibilities… lol
I’m assuming you are talking about browser extensions which allow for users to set their useragent to IE6? If so, please advise and I’ll check them out.

And a friendly bump on the PHP related question. :slight_smile:
Thanks!

The USER-AGENT header is so unreliable I think you should avoid using it if possible.
Why are you testing for it? If for CSS I would use conditional comments to load in special CSS files. If it’s a code thing, try testing for support of the code in question.

You can’t send anything to the browser before you send a header - whitespace is a thing. The error tells you what line the output (that got sent) is on, and what line the header call is on.

Ah, my mistake. I put the code at the very top of the page (above the doctype) and it seems to work fine now. :slight_smile:
Thanks for your help, hash!

The reason I’m setting the IE6 specific page is because I’m discontinuing support for it and telling people they need to upgrade their browser in order to view my website. Didn’t want to bother with ie.css because I’d rather educate users that IE6 is outdated and unsafe for browsing the web with. Hopefully it won’t be an issue for 99% of the users and I’m sure they will find immediate improvements with their new browser.

I can see the scarce possibility of it being an issue for libraries or places without access to downloading and installing files, but hopefully they will be up with the times by now anyways. And if they aren’t then hopefully the user will ask the establishment for their reasoning… it should at the very least get them thinking. I think for most IE6 users, they are running Windows XP and just don’t understand that they should update Internet Explorer because Microsoft hasn’t prompted them to make the upgrade — or if MS did, then for whatever reason they didn’t bother with it.

Are a lot of people still even using IE6? With sites like YouTube prompting users to upgrade I just can’t see IE6 sticking around much longer…

Your thoughts/suggestions on this are greatly appreciated.
Thanks!

This should be fine


<!--[if lte IE 6]>
<meta http-equiv="refresh" content="0; url=somewhere.html" />
<![endif]-->

All good. :slight_smile: Got it working perfectly with PHP (and no messy markup)
Thanks again