-2

So I know that I could actually do display:none; on all my posts and other content.

The problem with that is that you could anyways see the content inside the source code (pretty sure that 99.9999% of IE8 users don't even know about source code option, but want to hide it from source code anyways... ). What I would like instead to do is to not get any code at all besides maybe display something like this both on page and in source code:

<!--[if lte IE 8]>
    <h2>You should update your browser version or choose another. Otherwise the content will not be visible for Internet Explorer users or below.<h2>
<![endif]-->

(It's a WordPress website)

Marc
  • 4,661
  • 3
  • 40
  • 62
user4312416
  • 137
  • 2
  • 9
  • 1
    Why would you want to do this? That would require user-agent sniffing in the back-end. – Alexander O'Mara Feb 21 '15 at 20:51
  • Is there a specific reason you don't want it to be seen even via source code? The only reason I could think for hiding it at that level is a security issue, but a user having IE8 wouldn't merit this. – cchapman Feb 21 '15 at 20:51
  • 1
    This seems like a fairly silly requirement. Even if you delivered only a blank page to an IE8 user, all they have to do is go download Chrome or Firefox or a newer version of IE and then they can see your source. This seems like you're trying to triple lock the back door when the front and side doors are wide open which is pretty much a waste of time. – jfriend00 Feb 21 '15 at 20:53
  • Perhaps a more effective approach would be to design two experiences, one for the browsers that support the features you need and one for browsers that don't. This would allow you to provide experiences for older browser and for those using non-traditional browsers, such as screen readers and other accessible devices. – Lance Leonard Feb 21 '15 at 21:36

3 Answers3

1

Warning: Be wary of using Jack Zelig's answer above, it will compromise your server's security since it's running an eval on a function that parses the user agent. An eval() accesible to users can be exploited by running code on your server.

This question has been answered more thoroughly here:

if (preg_match('/MSIE\s(?P<v>\d+)/i', @$_SERVER['HTTP_USER_AGENT'], $B) && $B['v'] <= 8) {
    // Browsers IE 8 and below
    // Don't render regular template files to these users
    // e.g.: include 'update-your-browser.php'
} else {
    // All other browsers
    // Offer a version of the regular site
}

Other similar solutions can be adapted: Can I detect IE6 with PHP?

Sidenote: also, avoid using /e on regular expressions since it will also evaluate any code included on whatever you are parsing.

Eduardo
  • 63
  • 7
0

The short answer is yes, it could be done.

But for what it sounds like you are describing, I would say you shouldn't ever worry about what people see in your source code unless it is a security issue (in which case it should be hidden from everyone, with every type of technology that might be able to see it). The presentation layer is really all that matters to your visitors, in which case the display:none is sufficient.

cchapman
  • 3,269
  • 10
  • 50
  • 68
0

Try this in index.php of your theme folder:

<?php
function iever($compare=false, $to=NULL){
    if(!preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $m)
     || preg_match('#Opera#', $_SERVER['HTTP_USER_AGENT']))
        return false === $compare ? false : NULL;

    if(false !== $compare
        && in_array($compare, array('<', '>', '<=', '>=', '==', '!=')) 
        && in_array((int)$to, array(5,6,7,8,9,10))){
        return eval('return ('.$m[1].$compare.$to.');');
    }
    else{
        return (int)$m[1];
    }
}

if(iever('<=', 8)){ 
  <?php include (TEMPLATEPATH . '/shared/header.php' ); ?>
  <!-- YOUR CONTENT -->
  <?php 
    include (TEMPLATEPATH . '/shared/sidebar.php' );
    include (TEMPLATEPATH . '/shared/footer.php' ); 
  ?>
} else {
  echo("Oh noes. IE8 or below. Maybe");
}

If that works, let me know in a comment and I'll find out which action to hook into (maybe init?) so that it can be done for every page.

I got the browser sniffing function from here.

You know that browser sniffing is bad, right?

James Hibbard
  • 16,490
  • 14
  • 62
  • 74
  • 1
    This is not secure. A person could change her user agent and make a request to execute code in your server. Try to avoid using `eval`, at least with inputs that are (or might be) generated by users. http://php.net/manual/en/function.eval.php – Facundo Matteo Aug 24 '17 at 13:51