On Tue, Sep 2, 2008 at 4:39 AM, Dave M G <martin@xxxxxxxxxxxxx> wrote: > PHP List, > > I have a script, part of which is taken from a script I found on the 'net, > which tries to detect the user agent of the browser accessing the site. One > of the reasons I'm doing this is to find out if the browser is a desktop or > mobile. > > Part of the code looks like this: > > $ua = strtolower($_SERVER['HTTP_USER_AGENT']); > $isDesktop = (strpos($ua, 'firefox') !== false) > || (strpos($ua,'mosaic') !== false) > || (strpos($ua,'msie') !== false) > || (strpos($ua,'opera') !== false) > || (strpos($ua,'mozilla') !== false) > || (strpos($ua,'w3c_css_validator') !== false) > || (strpos($ua,'w3c_validator') !== false); > > What's driving me crazy is that it successfully determines all the browsers > listed there, *except* mozilla. > > I have a log file which alerts me when an unknown browser comes through my > site, and it's chock full of messages telling me that a Mozilla based > browser has come by. There are a *lot* of Mozilla based browsers. > > Some examples from my logs of the browsers slipping by my test: > > HTTP_USER_AGENT: Mozilla/5.0 compatible; Yahoo! Slurp > HTTP_USER_AGENT: Mozilla/5.0 compatible; Googlebot/2.1 > HTTP_USER_AGENT: Mozilla/5.0 X11; U; Linux i686 > > In each case, the strpos() should have seen the mozilla agent and not > bothered logging it. > > It's not complicated code, especially considering it's successfully finding > msie and firefox. > > I can't imagine why Mozilla would be different. > > Any suggestions? Is there something about my code right in front of my face > that I'm not seeing? > > Any suggestions would be greatly appreciated. > > Thanks. > > -- > Dave M G > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Unless you are not getting that useragents on your php, it as to work... At least my test worked perfectly <?php var_dump( strpos( strtolower( 'Mozilla/5.0 compatible; Yahoo! Slurp' ), 'mozilla' )); var_dump( strpos( strtolower( 'Mozilla/5.0 compatible; Yahoo! Slurp' ), 'mozilla' ) !== false ); var_dump( strpos( strtolower( 'Mozilla/5.0 compatible; Googlebot/2.1' ), 'mozilla' )); var_dump( strpos( strtolower( 'Mozilla/5.0 compatible; Googlebot/2.1' ), 'mozilla' ) !== false ); var_dump( strpos( strtolower( 'Mozilla/5.0 X11; U; Linux i686' ), 'mozilla' )); var_dump( strpos( strtolower( 'Mozilla/5.0 X11; U; Linux i686' ), 'mozilla' ) !== false ); ?> -- Thanks for your attention, Diogo Neves Web Developer @ SAPO.pt by PrimeIT.pt