Jump to content

php includes with IE conditionals


Elemental

Recommended Posts

Hey Folks, Question about PHP Includes wrapped around IE conditional comments...I'm learning to use a php menu include for all my pages <?php include("navBar.php"); ?>, the menu (navBar.php) has css rollovers that IE6 does not render properly. I could simply make each menu option a clickable one just for IE6 but I thought I could do the following...Here's my html:

<div id="nav_footer"> <!-- ********** BEGIN nav_footer //--><?php include("navBar.php"); ?></div> <!-- *********** END nav_footer //-->
This works fine on IE7 and IE8, haven't tried IE9 yet but I would think it would work also...Here's what I tried to do for IE6:
<div id="nav_footer"> <!-- ********** BEGIN nav_footer //--><!--[if IE 6]><?php include("navBar-ie6.php"); ?><![endif]--></div> <!-- *********** END nav_footer //-->
This didn't work, though, the way I thought it should, it included the navBar.php not the navBar-ie6.php.Can I not use IE conditional comments this way with php?Peace,Elemental
Link to comment
Share on other sites

That doesn't really make sense... the PHP code is executed on the server and thus and isn't affected by comments, browsers, or anything to do with the actual markup or client-side environment.

Link to comment
Share on other sites

That doesn't really make sense... the PHP code is executed on the server and thus and isn't affected by comments, browsers, or anything to do with the actual markup or client-side environment.
Synook, Thanks for the reply, much appreciated.So, if I understand you, the IE conditional comment should work?I didn't copy and paste the code, trying to learn by writing it, so I may have written the code wrong in the original document; I'll take a look at it and see.Peace,Elemental
Link to comment
Share on other sites

Err, the conditional comment won't stop the PHP include from being executed, but it will prevent the output from affecting the document in browsers other than IE6.

Link to comment
Share on other sites

Err, the conditional comment won't stop the PHP include from being executed, but it will prevent the output from affecting the document in browsers other than IE6.
Synook, Thanks again for the reply.Sure enough, I opened the page with FF and no menu. It's in the source code but it shows it as a comment. Why is that, I thought IE conditionals only affected IE browsers?Peace,Elemental
Link to comment
Share on other sites

Right click on your page and select "View Source". Do the same for IE6 and Firefox... you shouldn't be seeing any difference in the code.Like Synook said, the PHP code is executed either way. It unconditionally outputs an HTML comment for all browsers. That comment is special for IE6, which is why only IE6 can show the contents from it.The thing you're doing doesn't really make sence because you can detect the browser on the server (though not as easily, I admit), and instead of doing the include for all browsers, you could do it just for IE6.

Link to comment
Share on other sites

Right click on your page and select "View Source". Do the same for IE6 and Firefox... you shouldn't be seeing any difference in the code.Like Synook said, the PHP code is executed either way. It unconditionally outputs an HTML comment for all browsers. That comment is special for IE6, which is why only IE6 can show the contents from it.The thing you're doing doesn't really make sence because you can detect the browser on the server (though not as easily, I admit), and instead of doing the include for all browsers, you could do it just for IE6.
boen_robot, Thank you for your input, much appreciated.I did look at the source code for FF and IE7 and yes, on both of them, it shows as a comment, only IE6 renders it on the page.Hence my confusion, I thought FF would render the menu. My understanding was that conditional comments such as this
<!--[if IE 6]><?php include("navBar-ie6.php"); ?><![endif]-->
only targeted IE browsers; in this case IE6.If it's not to much trouble, can you expand a bit on your last statement? How would you do a server side include, in my case a navigational menu, just for IE6 and still have all other browsers render a different menu?Peace,Elemental
Link to comment
Share on other sites

You can try to browser sniff on the server by looking at the value of $_SERVER['HTTP_USER_AGENT']. Print that out for several different browsers so you see what it looks like. The format and content is quite variable, and the number of browsers that identify themselves as mozilla is a bit surprising. You'll see.

Link to comment
Share on other sites

You can try to browser sniff on the server by looking at the value of $_SERVER['HTTP_USER_AGENT']. Print that out for several different browsers so you see what it looks like. The format and content is quite variable, and the number of browsers that identify themselves as mozilla is a bit surprising. You'll see.
Deirdre's Dad, Thank you for your input sir, as alway, much appreciated.I'm liking the jargon: sniffing, browsing, user agents... it's almost like reading a mystery-spy novel; okay, granted, with a little sponge-i-ma-gi-na-tion.Peace,Elemental
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...