MySpaza - How To
Web Design Tips and PC and Linux Related Information

Subscribe
 



    follow me on Twitter

    PHP User Agent Check Function - Users Browser Check
    php browser check function checking http_user_agent

    Added: 2008-05-19 08:45:57

    This is a simple function that will return the users browser type in an easy to read form, this function can be used to check for in-compatible browsers and redirect if required, just add some if() statements within you own script.

     function useragent() {
      $useragent = $_SERVER['HTTP_USER_AGENT'];
      //print $useragent;
      if(strchr($useragent,"MSIE 7.0")) return 'IE 7';
      if(strchr($useragent,"Firefox/2")) return 'FIREFOX 2';
      if(strchr($useragent,"MSIE 6.0")) return 'IE 6';
      if(strchr($useragent,"MSIE 5.5")) return 'IE 5.5';
      if(strchr($useragent,"MSIE 5.01")) return 'IE 5.01';
      if(strchr($useragent,"MSIE 4.01")) return 'IE 4.01';
      if(strchr($useragent,"MSIE 3.0")) return 'IE 3.0'; 
      if(strchr($useragent,"Opera")) return 'Opera';

     }

    Pre requisites - Alert function (The following requires this function)

    You may wish to not allow older browsers to use your site, using the useragent() and alert() functions we can achieve this with the following:

    <?

    if(useragent()=='IE 3.0' || useragent()=='IE 4.01') {

    alert("Your browser is too old to use this browser, please upgrade your browser and try again");

    }

    ?>

     

     




    Add a comment to this post
    Email confirmation is required for each post

    Name:
    Email:
    Comment:
     

    Comments from other users:




    Copyright MySpaza.Co.Uk - 2012