How do I browser block code in php?

Asked By 10 points N/A Posted on -
qa-featured

How do I block or restrict a particular browser from unregistered users?

<?php
if (eregi("MSIE",getenv("HTTP_USER_AGENT")) ||
eregi("Internet Explorer",getenv("HTTP_USER_AGENT"))) {
Header("Location: https://www.domain.com/ie_reject?;
exit;
}
?>
Will this code work? How do I browser block cod in php scripting language?

 

SHARE
Answered By 0 points N/A #153648

How do I browser block code in php?

qa-featured

 

Hello,
I have a simple example that will show you how to block a browser using PHP. I documented each line for you and here is the code:
<?php
// This line will check what browser the user is using.
$agent = $_SERVER['HTTP_USER_AGENT']; 
//This line will print to the screen the type of browser the user is using. You can keep the line or delete it .
echo $agentToBlock;
// Allow certain browser and disable others. This is a condition statement used to check if the browser is Internet explorer
if (preg_match("/bMSIEb/i", $agent)) 
{
   echo 'You are using IE, you can pass.';
} 
  // Other browsers are not allowed
else if (preg_match("/bFirefoxb/i", $agent))
{
   echo 'You are using Firefox, goodbye.';
  // use this function to abort.
   exit(); 
   }
?>
I hope this is useful.

Related Questions