We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20371
    • 58 Posts
    Hi All,

    I’m having a first look at modx, until now I’ve been using wordpress and so far... modx looks like a MUCH better option for me.

    Rightly or wrongly, I am in the habit of detecting the users browser in php via $_SERVER[’HTTP_USER_AGENT’] and subsequently sending browser specific css to the user, to ensure that my page looks the same in ie and non-ie browsers. I know this method doesn’t suit everyone, as it means you need two different sets of css - I like it, because it avoids ugly html conditional statements, and having to make one style sheet work in all browsers.

    So.. I tried using a snippet to detect the browser, and return a specific chunk based on the user browser.

    The problem is that array reference ($_SERVER[’HTTP_USER_AGENT’]) always returns the same string, regardless of which browser I access the modx page with:
    Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.9 Safari/533.2


    so is there any way I can get the correct browser with a php snippet ?
    thanks in advance

    edit.. just noticed that the alternative $modx->getUserData(); is the same.. always returns the same info, regardless of which browser I use.
      • 3749
      • 24,544 Posts
      It’s generally better to use IE conditional comments around the CSS includes in the template. It’s significantly faster and you don’t run into caching problems (which I think is what you’re seeing).

      http://en.wikipedia.org/wiki/Conditional_comment



        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 20371
        • 58 Posts
        ahh, caching.. thanks very much for that. using the non-cached snippet call [!snippet!] now and its working a peach. Thanks for the help!