Hi everyone.

Is there any script or programme I can install to record what browsers are visting my site? I would use this so I could cater for each browser and then to re-direct them to relevent content.

Also if anyone knows a decent php browser detection script (and how I add it), it would be appreciated.

Thanks 😃

    Sorry I forgot to mention that I'm new to php and if I see the code in whole I will understand it alot better that strugling to put together my own. Which I have been doing, but with constant errors. Thanks

      Here's a tiny snippet to get you started (you will have to look up the various browser codes yourself)

      function browser_detect() {
        if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE') !== false) {
          return 'IE';
        } else if //go on from here
      }
      

      Hope it helps you out

        BTW - if you are checking for the presence of the word Mozilla,
        it is present in IE as well.
        For instance, I am using IE 6.0 right now, and here's the string :
        Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; yie6_SBC)

        So the best way to find out if it's IE would be to do what
        I posted (check for MSIE in the string)

          Originally posted by wapchimp
          I have this but I am getting errors:

          $ok = "http://www.wapchimp.pwp.blueyonder.co.uk/t610lite.htm";
          $bad = "http://www.wapchimp.com/web";

          $Browser = $HTTP_USER_AGENT;
          $BrowserSplit = explode("/", $HTTP_USER_AGENT);
          $Machine = $BrowserSplit[0];

          if($Machine == "Opera" || $Machine == "Mozilla") {
          header("location: $bad");
          }
          else {
          header("location: $ok");
          }

          If you are using a newer version of PHP, I don't think $HTTP_USER_AGENT works. Use $_SERVER['HTTP_USER_AGENT'] or $HTTP_SERVER_VARS['HTTP_USER_AGENT']

          Like I said, this code works :

          function getBrowser() {
            if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE') !== false) {
          	return 'IE';
            } else if(strpos($_SERVER['HTTP_USER_AGENT'],'Gecko') !== false) {
              return 'Mozilla/Firefox';
            }
          }  

          So then you would just do :

          if(getBrowser() == 'IE') { header("Location: $good\n"); } else
          { header("Location: $bad\n"); }
          
            Write a Reply...