Re: [PHP] Mozilla user agent escapes detection

2008-09-02 Thread Diogo Neves
On Tue, Sep 2, 2008 at 4:39 AM, Dave M G [EMAIL PROTECTED] 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


Re: [PHP] Mozilla user agent escapes detection

2008-09-02 Thread Jochem Maas

Dave M G schreef:

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.


Mozilla !== mozilla

stripos is the case-insenstive version of strpos



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


these 2 are bots btw.


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.


STW? plenty of people offering code that attempts to detect mobile devices, 
e.g.:

http://www.andymoore.info/php-to-detect-mobile-phones/

also I'd offer a link in the top of your site pointing to the mobile site
(and vice-versa) in order to:

1. allow bots to visit both.
2. in case your code guessed incorrectly for some user(s)

I'd also check the UA string specifically for bots first and just let them
through ... they are neither desktop nor mobile browsers.

additionally you might consider how you want to accomodate text browsers
(which is kind of what a bot is)



Thanks.




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Mozilla user agent escapes detection

2008-09-02 Thread Richard Heyes
 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.

Try another detection script. Eg my own:

http://www.phpguru.org/static/browser.html

Or the Javascript version it stems from. Or...

-- 
Richard Heyes

HTML5 Graphing for IE7, FF, Opera and Safari:
http://www.phpguru.org/RGraph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Mozilla user agent escapes detection

2008-09-02 Thread Dave M G

Richard,

Thanks for responding.


http://www.phpguru.org/static/browser.html


I may just do that. If it works out for my needs, I'll let you know.

Really, right now I'm doing browser detection to simply sort incoming 
browsers into desktops, bots, and mobile. If I can get your script to do 
that, then sweet.


By the way, another thing I'm trying to do is reliably test to see if a 
browser accepts cookies. I just looked through your PHP blog, and didn't 
see that specifically listed, but since I'm emailing you already, may I 
ask if you have a script that does that? Or a good recommendation?


--
Dave M G

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Mozilla user agent escapes detection

2008-09-02 Thread Shawn McKenzie

Jochem Maas wrote:

Dave M G schreef:

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.


Mozilla !== mozilla


Look at the code: strtolower('Mozilla') === 'mozilla'

-Shawn


stripos is the case-insenstive version of strpos



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


these 2 are bots btw.


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.


STW? plenty of people offering code that attempts to detect mobile 
devices, e.g.:


http://www.andymoore.info/php-to-detect-mobile-phones/

also I'd offer a link in the top of your site pointing to the mobile site
(and vice-versa) in order to:

1. allow bots to visit both.
2. in case your code guessed incorrectly for some user(s)

I'd also check the UA string specifically for bots first and just let them
through ... they are neither desktop nor mobile browsers.

additionally you might consider how you want to accomodate text browsers
(which is kind of what a bot is)



Thanks.





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Mozilla user agent escapes detection

2008-09-02 Thread Richard Heyes
 By the way, another thing I'm trying to do is reliably test to see if a
 browser accepts cookies. I just looked through your PHP blog, and didn't see
 that specifically listed, but since I'm emailing you already, may I ask if
 you have a script that does that? Or a good recommendation?

Just send a cookie to the browser, rfresh the page (or redirect to
another page) and then test for its existence (in $_COOKIE).

-- 
Richard Heyes

HTML5 Graphing for IE7, FF, Opera and Safari:
http://www.phpguru.org/RGraph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Mozilla user agent escapes detection

2008-09-02 Thread Jochem Maas

Shawn McKenzie schreef:

Jochem Maas wrote:

Dave M G schreef:

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.


Mozilla !== mozilla


Look at the code: strtolower('Mozilla') === 'mozilla'


oh crap :-)



-Shawn


stripos is the case-insenstive version of strpos



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


these 2 are bots btw.


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.


STW? plenty of people offering code that attempts to detect mobile 
devices, e.g.:


http://www.andymoore.info/php-to-detect-mobile-phones/

also I'd offer a link in the top of your site pointing to the mobile site
(and vice-versa) in order to:

1. allow bots to visit both.
2. in case your code guessed incorrectly for some user(s)

I'd also check the UA string specifically for bots first and just let 
them

through ... they are neither desktop nor mobile browsers.

additionally you might consider how you want to accomodate text browsers
(which is kind of what a bot is)



Thanks.








--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Mozilla user agent escapes detection

2008-09-02 Thread Diogo Neves
On Tue, Sep 2, 2008 at 5:49 PM, Jochem Maas [EMAIL PROTECTED] wrote:

 Shawn McKenzie schreef:

 Jochem Maas wrote:

 Dave M G schreef:

 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.


 Mozilla !== mozilla


 Look at the code: strtolower('Mozilla') === 'mozilla'


 oh crap :-)



 -Shawn


 stripos is the case-insenstive version of strpos


 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


 these 2 are bots btw.

  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.


 STW? plenty of people offering code that attempts to detect mobile
 devices, e.g.:

 http://www.andymoore.info/php-to-detect-mobile-phones/

 also I'd offer a link in the top of your site pointing to the mobile site
 (and vice-versa) in order to:

 1. allow bots to visit both.
 2. in case your code guessed incorrectly for some user(s)

 I'd also check the UA string specifically for bots first and just let
 them
 through ... they are neither desktop nor mobile browsers.

 additionally you might consider how you want to accomodate text browsers
 (which is kind of what a bot is)


 Thanks.





 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

 Anyway, this code is working...
I changed my useragent in Firefox and it worked pretty well to me...


-- 
Thanks for your attention,

Diogo Neves
Web Developer @ SAPO.pt by PrimeIT.pt


[PHP] Mozilla user agent escapes detection

2008-09-01 Thread Dave M G

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