Justin
Justin

Reputation: 137

PHP Browser Conditional

What I am trying to do is making a PHP Conditional specifically for IE9. What I've tried so far are these two PHP Browser Conditionals

if(preg_match('/(?i)msie [9]/',$_SERVER['HTTP_USER_AGENT'])) 
{ 
   //my code here 
   exit; 
}

if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) 
{
   //my code here 
}

Did I write them incorrectly? Am I missing something?

Upvotes: 0

Views: 142

Answers (2)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324840

You should not filter browsers for any reason. Instead, use feature detection to see if the browser is capable of what you are trying to do.

Aside from that, the User-Agent string is unreliable and can literally be set to anything, or even not sent at all.

Upvotes: 0

Jose Vega
Jose Vega

Reputation: 10258

if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 9.') !== false) { 
  //my code here 
   exit; 
}

Upvotes: 1

Related Questions