ie attempt notes:
<?php
$ua = $_SERVER['HTTP_USER_AGENT'];
if ((stristr($ua, "MSIE") ¦¦ stristr($ua, "Internet Explorer")) {
echo 'IE Detected';
}
?>
- putting stuff on separate lines makes your code more readable
- you had a line ending (";") after your if clause, so the next 'echo' line wouldn't be conditional on the if.
gecko attempt notes:
<?php
if (!(strpos($HTTP_USER_AGENT,'Gecko') === false)) {
echo("Gecko yes");
}
?>
- since you have a! (means 'not'), you want this to output "Gecko yes" when the statement is
not false, and not when it is
not true.
- this is a bit of an odd construction, and that might have thrown you, but it's pretty standard and one of the best ways of doing things. strpos returns 0 when a string is found at the very beginning of the haystack string - 0 being the offset that it's found out. so note also that I:
- added an = sign, changing your operator from == to === .
- this is a strict comparison. 0 == false (normal PHP comparison), however 0 does not === false, only false === false. === is the 'strict comparison' operator, meaning it only registers true not only when the "value" of the stuff on both sides is the same, but also when their type is the same. So if strpos turns up 0 if the string is at the beginning, it doesn't return false.