i dont know rite code so i was wondering if someone could help. I want it todo this,
If (users browser = internet explorer)
{
echo 'Sorry, I'm anti IE so you cant view my site;
}
else
{
echo "Welcome";
}

    You can try this:

    <?php
    
    $my_browser = get_browser(null,true);
    
    echo "Browser type: " . $my_browser['parent'];
    
    if (  strstr($my_browser['parent'], 'IE')  )
      {
       echo "Sorry, I'm anti IE so you cant view my site";
      }
    else
      {
      echo "Welcome";
      }
      ?>
    

    For the above to work you need to have the php.ini point to the browscap.ini for more info check this: http://us2.php.net/function.get-browser

    I am not sure if there is much efficient way of doing this, but this works.

      Of course a more global example would be to use $_SERVER['HTTP_USER_AGENT']. This will output something like:

      Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)

      It is possible to write a quick function to figure the browser:

      <?php
      
      function check_browser()
      {
        $browser = $_SERVER['HTTP_USER_AGENT'];
        $browser = substr( $browser, 0, strpos($browser, '/') );
        return $browser;
      }
      
      if( (check_browser() == 'MSIE') || (preg_match("@(MSIE[\s\d\.]*)\)@", check_browser()) )
      {
        // The die will kill this script, so nothing else will display
        // Probably something a little more catered to you just in case
        // you plan on doing other things in the same script, this kills it.
        die('Sorry, I\'m anti-IE.  You can\'t view my site with that browser.');
      }

      Something like that could work too if you can't point your php.ini to the browsercap settings....

      HERE is an article on denying user access by user-agent in a .htaccess file. Much better than per-script.

      ~Brett

        Write a Reply...