Monday, July 29, 2013

How to know if the browser is IE in PHP

Hi. This is a small code to check the browser is Internet explorer or not using the PHP.
<?php
if(preg_match('/(?i)msie [1-8]/', $_SERVER['HTTP_USER_AGENT']))
{
   // The browser is IE 
   // write your code here
}
else
{
   // The browser is other than IE
   // write your code here
} 
?>

If you are executing the above code in Internet explorer browser then if condition will execute. and if you are executing the code in other than Internet explorer then else condition will be executed.

Thank you

No comments:

Post a Comment