-1

I am testing this code but "hello" gets shown in every browser. Normally it should only show up in MSIE.

Did I forgot something?

   $usragent = $_SERVER['HTTP_USER_AGENT'];

    echo $usragent;

    if(
    ((strlen(strstr($usragent,"Firefox")) <= 0)) || 
    ((strlen(strstr($usragent,"Chrome")) <= 0)) ||
    ((strlen(strstr($usragent,"Safari")) <= 0))
        )
        {
        echo "hello";
        }
Evert
  • 93,428
  • 18
  • 118
  • 189
Mike
  • 3,200
  • 5
  • 22
  • 33

1 Answers1

-1

I suggest using the php function strpos. Example:

if (strpos($usragent,'MSIE') == true) {
    echo 'hello';
}

To complete your case, example:

if (strpos($usragent,'Firefox') || strpos($usragent,'Chrome') || strpos($usragent,'Safari')) {
    echo "hello";
}
Arjen
  • 289
  • 2
  • 4
  • 11
  • 2
    You fail to recognize that `strpos()` returns the position of the found string, which can be zero if it is at the start. That zero will evaluate to false when compared with true, and your code will give wrong results. Always compare strictly with false! `if (strpos() !== false) { echo "found";}` – Sven Oct 13 '13 at 19:57