Search code examples
phpconcrete5

How to get user's browser name and append it as a class to <body> tag


I'm doing a theme for Concret 5 and I'm not sure if there's already a similar solution to my problem from Concrete 5.

I want to append the user's browser name to my <body> so I can target them via css later

Example how the PHP should render the name to my body tag.

<body class="ie5" >
or
<body class="safari" >

CSS Sample I'll use later

body.ie div#id { background: #ccc }
body.safari div#id { font-size: 15px; }

Solution

  • as per your other requirement that wasn't asked before

    for getting all browser's name

            $u_agent = $_SERVER['HTTP_USER_AGENT'];
            $ub = '';
            if(preg_match('/MSIE/i',$u_agent))
            {
                $ub = "Internet Explorer";
            }
            elseif(preg_match('/Firefox/i',$u_agent))
            {
                $ub = "Mozilla Firefox";
            }
            elseif(preg_match('/Safari/i',$u_agent))
            {
                $ub = "Apple Safari";
            }
            elseif(preg_match('/Chrome/i',$u_agent))
            {
                $ub = "Google Chrome";
            }
            elseif(preg_match('/Flock/i',$u_agent))
             {
                $ub = "Flock";
            }
            elseif(preg_match('/Opera/i',$u_agent))
            {
                $ub = "Opera";
            }
            elseif(preg_match('/Netscape/i',$u_agent))
            {
                $ub = "Netscape";
            }
    

    now you can show browser name

    <body class="'. $ub ." >