Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[SOLVED] User Agent Detection


Go to End


9 Posts   3581 Views

Avatar
steve_nyhof

Community Member, 224 Posts

19 January 2010 at 9:54pm

I ended up using a lightbox to create a popup - but this also worked to find the browser..
See this thread for more options...
http://us2.php.net/manual/en/function.get-browser.php#88923

Add to the Page.php below the class
class Page_Controller extends ContentController {

function get_user_browser()
{
    $u_agent = $_SERVER['HTTP_USER_AGENT'];
    $ub = '';
    if(preg_match('/MSIE/i',$u_agent))
    {
        $ub = "ie";
    }

   
    return $ub;
} 

Then in the template...

 <% if get_user_browser == ie %>
Do something for IE
 <% else %>
Else do something for all others
 <% end_if %>

Hope this helps someone
Steve

Go to Top