Simon
Simon

Reputation: 602

"if lt IE 9" equivalent in PHP?

Is there an equivalent in PHP for the HTML Syntax:

<!--[if lt IE 9]>
    <script src="/js/html5/html5shiv.js"></script>
<![endif]-->

?

Upvotes: 2

Views: 4178

Answers (3)

RDK
RDK

Reputation: 4560

Use native php function get_browser();

And read this post. Try this code:

    $browser = get_browser();

    switch ($browser->browser) {
        case "IE":
            switch ($browser->majorver) {
                case 6:
                case 5:
                    echo '<link href="ie5plus.css" rel="stylesheet" type="text/css" />';
                    break;
                case 9:
                    echo '<link href="ie5plus.css" rel="stylesheet" type="text/css" />';
                    break;
                default:
                    echo '<link href="ieold.css" rel="stylesheet" type="text/css" />';
            }

            break;
}

Upvotes: 6

Jon
Jon

Reputation: 437904

You can do User Agent detection in PHP manually using $_SERVER['HTTP_USER_AGENT'], or you can use a ready-made solution such as get_browser (which admittedly is kind of a hassle to set up).

However, usually there's not so much to be gained from doing this on the server (although there are legitimate cases, I 've needed to do this myself). Perhaps you can achieve the aim on the client side?

Upvotes: 1

bogatyrjov
bogatyrjov

Reputation: 5378

Read about $_SERVER opportunities. Specifically, $_SERVER['HTTP_USER_AGENT']. You can also detect the browser using Javascript and send it to Your server-side PHP code using AJAX

Upvotes: 0

Related Questions