Forum Moderators: coopster
One which includes the file either way, so that is not good:
<?php
echo '<!--[if IE]>';
include ("Borders/IEnoJavaMenu.php");
echo '<![endif]-->';
?>
And two which will not get the include either way, so that is not good:
<?php
echo '<!--[if IE]>'.include ("Borders/IEnoJavaMenu.php").'<![endif]-->';
?>
What is this "if IE" you say? It can be detailed here
[quirksmode.org...]
or here
[quirksmode.org...]
if you never saw it before.
Why do I use it you say? Because if JavaScript detects the browser that is, let's say, Opera that is set to disquise itself as IE, then the JavaScript thinks Opera is IE. But with the nifty little if IE, Opera is not detected as IE.
Anyway, I use this conditional statement all the time and it works great in IE, Opera, Mozilla, and Netscape. What I tried originally was
<!-- IE menu with no java -->
<!--[if IE]>
<?php include ("Borders/IEnoJavaMenu.php");?>
<![endif]-->
But of course the PHP gets read either way when the page is parsed. What would be ideal, is for the PHP not to be recognized when inside an HTML comment.
Again, thank you for your input in this odd request.
as others said, the javascript is run on the client after the page is sent so by then its too late
you could have a "loading" page which uses javascript to redirect to either "?client=ie" or "?client=notie" if you really wanted to use javascript to detect the browser then have the PHP script check $_GET['client'], however that would be a horrible way to do it and you're better off using the client identified in the request and hope they aren't deliberately requesting the wrong content (which if they are - it really is their fault for messing with it, and they cant expect things to work if they try and prevent you being able to detect the browser to get them to work)
A quick and dirty check for Internet Explorer would give something like this:
<?php if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
include ('file1.php');
}
else {
include ('file2.php');
};
With that I'm checking the user agent string for "MSIE" (all IE browsers should include that) and including file1.php, otherwise I'm including file2.php. You'll need to add further checking for Opera which includes the string "MSIE" when spoofing its user agent (Opera always has the word "Opera" in the string, spoofing or not).
The code I finally went with for anyone else who has the same problem is:
<?php if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") && strstr($_SERVER['HTTP_USER_AGENT'], "Opera")) {
echo 'Stop trying to cloak your browser!';
}
else if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
include ('Borders/IEnoJavaMenu.php');
}
?>
The IEnoJavaMenu.php then swaps the JS code to make IE recognize my hover LI menu with an alternate menu if JS is disabled. The code above saves download time for non-IOE browsers.
Thank you again!