-1

Is it possible to control which files get included by looking at the browser type?

For example if I'm using:

<?php include("includes/nav.php"); ?>

but for all IE browser versions I'd like to call a different file, nav_ie.php, can that be done, and if so, how would I go about it?

5
Contributors
9
Replies
12
Views
7 Years
Discussion Span
Last Post by FlashCreations
0

http://php.net/manual/en/function.get-browser.php

<?php
echo get_user_browser();
function get_user_browser()
{
    $u_agent = $_SERVER['HTTP_USER_AGENT'];
    $ub = '';
    if(preg_match('/MSIE/i',$u_agent))
    {
        $ub = "ie";
    }
    elseif(preg_match('/Firefox/i',$u_agent))
    {
        $ub = "firefox";
    }
    elseif(preg_match('/Safari/i',$u_agent))
    {
        $ub = "safari";
    }
    elseif(preg_match('/Chrome/i',$u_agent))
    {
        $ub = "chrome";
    }
    elseif(preg_match('/Flock/i',$u_agent))
    {
        $ub = "flock";
    }
    elseif(preg_match('/Opera/i',$u_agent))
    {
        $ub = "opera";
    }

    return $ub;
}
?>
0

If you are attempting to create an IE compliant page you may also want to look into IE conditional comments. Anything between them is only shown by the appropriate version of IE.

<!--[if IE 6]>
  <b>IE 6 Only!</b>
<![endif]-->
0

I don't see where to put my include code. This exactly what I need for IE6. I already created my compliant menu, but I don't know how to call the IE6 compatible navigation.

0

I think he just gave you the answer.

<!--[if IE 6]>
  <?php include('includes/nav.php'); ?>
<![endif]-->

Edited by baudday: n/a

0

Ahh...Well now I feel like a dummy. That makes sense. So I guess my next question would be if it's not IE6 I want it to call my default nav so my code looks something like this.

<!--[if IE 6]>
<?php include('nav-ie6.php'); ?>
<![endif]-->
<?php } else ( ) { ?>
<?php include("nav3.php"); ?>

I also have conditional codes for css set for IE7 and IE 8 that look like the following and are currently working on the site.

<!--[if IE 7]><link rel="stylesheet" type="text/css" href="http://antimicrobial.com/wp-content/themes/default/ie.css" /><![endif]-->
<!--[if IE 8]><link rel="stylesheet" type="text/css" href="http://antimicrobial.com/wp-content/themes/default/style.css" /><![endif]-->
0

you can put the code that you would normally want loaded and then only put the if cases for the various browsers. so your normal code would always get loaded UNLESS the user is using IE6, 7, 8

0

The 2 lines ending in css are already up on the site and working. These just call compliant stylesheets. The first bit of code pulls from 2 different menus. I want to use the same menu on everything other than IE6.

So like I said if you're using the extremely old and crappy IE6 you'll see the javascript menu. If you're using any other browser you should see the jquery menu.

0

Try this:
Include the normal navigation as if every browser required it but enclose it in a tag with a special class (I would use something like noie6). Then include the IE nav in between the IE conditional tags and include the styling in the head as you already have done.

<div class="noie6">
<?php @include("normal-nav.php"); ?>
</div>

<!--[if IE 6]><?php @include("ie6-nav.php"); ?>
<![endif]-->

Now all you have to do is include this line of CSS in your IE6 stylesheet (The one included in the conditional tag):

div.noie6 { display: none; }

This way on all IE6 browsers the normal navigation will be hidden. Does this solve your problem?

Edited by FlashCreations: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.