• Resolved marcopolo

    (@marcopolo)


    Hi,

    I’m using a modified Blix theme, which behaves differently in different browser/platform combos. The cleanest solution appears to be a bit of browser sniffing PHP dropped into the header, e.g.,

    ‘<?php if (eregi(“MSIE”,getenv(“HTTP_USER_AGENT”)) ||
    eregi(“Internet Explorer”,getenv(“HTTP_USER_AGENT”))) { ?><link rel=”stylesheet” type=”text/css” href=”<?php bloginfo(‘stylesheet_directory’); ?>/style-ie.css”/>
    <?php } else { ?>
    <link rel=”stylesheet” type=”text/css” href=”<?php bloginfo(‘stylesheet_directory’); ?>/style.css”/>
    <?php } ?>’

    This works fine except when I try to add an elseif statement for Mac detection:

    ‘<?php elseif (eregi(“MACOS”,getenv(“HTTP_USER_AGENT”)) ||
    eregi(“Safari”,getenv(“HTTP_USER_AGENT”))) { ?><link rel=”stylesheet” type=”text/css” href=”<?php bloginfo(‘stylesheet_directory’); ?>/stylemac.css”/>’

    This stops any theme from loading. The browser displays a blank screen.

    This is probably just a glitch in my syntax, but I don’t know enough about PHP to locate the problem.

    Can any of you PHP jocks out there spot the problem?

    Thanks in advance.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Not sure of the syntax, but generally speaking, conditional statements in the CSS is the “proper” way of handling browser incompatibilities.

    Thread Starter marcopolo

    (@marcopolo)

    Yea, I tried the CSS hacks first.

    There are not sufficient filters to sort out browser/platform issues I encountered. For example, Firefox 1.5 interprets the theme/css differently depending on whether it’s running on Windows or a Mac.

    For reference, the site I’m working on is here: https://www.pratt-union.org/

    I’ve never heard of FF rendering differently in mac and windoze. Right now, the site loads winfox.css even though I’m on a mac.

    My personal opinion, look at the CSS and see what the issues are, and use valid XHTML and CSS, then hack for IE. FF should render valid code in either machine the same.

    Thread Starter marcopolo

    (@marcopolo)

    OK, finally got the syntax right for the PHP — I’d dropped a bracket. Here’s the working code:

    <!–the following bit is the browser/platform detect –>

    <?php if (eregi(“MSIE”,getenv(“HTTP_USER_AGENT”)) ||
    eregi(“Internet Explorer”,getenv(“HTTP_USER_AGENT”))) { ?><link rel=”stylesheet” type=”text/css” href=”<?php bloginfo(‘stylesheet_directory’); ?>/stylewinie.css”/>

    <?php } elseif (eregi(“MACOS”,getenv(“HTTP_USER_AGENT”)) ||
    eregi(“Safari”,getenv(“HTTP_USER_AGENT”))) { ?><link rel=”stylesheet” type=”text/css” href=”<?php bloginfo(‘stylesheet_directory’); ?>/stylemac.css”/>

    <?php } else { ?>
    <link rel=”stylesheet” type=”text/css” href=”<?php bloginfo(‘stylesheet_directory’); ?>/stylewinfox.css”/>
    <?php } ?>

    <!– end of browser/platform detect –>

    You can check the result here: https://www.pratt-union.org/.

    I’ve spent days on this problem and I think this is by far the cleanest solution.

    Even if there were CSS hacks that could discern Firefox from Safari from IE7, there are no CSS filters for platform. And Firefox renders differently when it’s running on a Mac OS than when it’s based on Windows. Until that problem is solved (probably never), you’re better off using PHP to interrogate the User_Agent.

    Thanks for the help.

    Still giving me winfox style on a mac FF 2.

    I read a lot of CSS experts’ sites, and they would argue with your assessments. To each his own.

    THANK YOU!!! This post was a gift from god!

    I’m just wondering if there is any way of specifying browser versions using this script?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Auto Theme Switch — PHP syntax ?’ is closed to new replies.