Full-Featured PHP Browser Detection - PHP Notice - Undefined
cgrymala
Status: New User - Welcome
Joined: 09 Mar 2009
Posts: 2
Reply Quote
Greetings!
First of all, I apologize to the webmaster of Tech Patterns. I used the "Contact" form to send a message similar to what I am about to post, because I completely overlooked the link to the support forums.

Secondly, I want to thank the developers, as this script is a great resource for the CMS I am developing.

Now, onto my issue/comment.

After activating the Full-Features PHP Browser Detection script to detect and log various information about our Web site visitors, I noticed our apache error log beginning to fill up with errors.

I am using the following line of code to invoke the functions inside the browser detection script:
:: Code ::
list($bname,$bvers, , , ,$osname,$osvers, ,$browsebot) = browser_detection('full');


As such, my apache error log was logging hundreds of errors similar to the following each day:
:: Code ::
PHP Notice:  Undefined offset:  16 in /var/www/browser-detection.php on line 463


I did some digging, and discovered that the problem only occurs when a "bot" visits the site. That makes sense. Since bots don't really report an operating system, it's difficult to detect the specific OS and OS version, so the which_os function was throwing PHP notices when trying to run the function.

As a simple work-around in my situation, I replaced line 371 of the December 2008 version of this script with the following, which simply checks to see if the visitor was detected as a bot before trying to run the which_os function.

If it is a bot, we simply return the information "BOT" as the OS and "Unknown" as the version number.

:: Code ::
      $a_os_data = ($type != 'bot') ? which_os( $browser_user_agent, $browser_name, $version_number ) : array('BOT','Unknown');


I hope that helps some other people that may have noticed the same issue. If anyone else has a better work-around, I would be very interested in seeing it. Thank you.
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 3922
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
interesting comments, thanks

That undefined offset issue is one I haven't been able to reproduce unfortunately, and it has also appeared on the basis of a php server configuration which I have never experienced, but which does exist since users have reported it a few times, especially a problem on lower end servers I believe.

it looks to me, though I'd have to check the code, that os should be seeing the bot status, but the problem with these pesky bots is that they fake their identities so much that they aren't very predictable.

And the script doesn't really keep up with the latest bot names except for the big players like search engine bots, even there that seemed like a largely lost cause.

Your solution seems workable to me too, but I'm wondering if there's a more elegant way to handle that issue.

On my servers, if I emulate for example googlebot, this is what the OS returns using the system information script output:

:: Code ::
Operating System:

(version unknown)
Current Browser / UA:

User Agent: Googlebot
Full Version Info: 2.1
XHTML support: Yes
System Language

Primary Language id: en-us
Primary Language:
English (United States)
Current Screen Resolution

1280 x 1024 pixels
JavaScript

JavaScript is enabled.
Cookies

Cookies are enabled


which is generated by this test:
:: Code ::
elseif ( $browser_info[6] == '' )
         {
            $os .=  ' (version unknown)';
         }


This largely confirms that the core undefined offset bug in some web servers' php ini is doing something that I honestly do not know how happens, but this isn't the first report of this issue, and it won't be the last until the actual core cause can be resolved adequately.

It's almost certainly a php.ini setting in the server, but what it is, I do not know, the offset should not be undefined, it is defined, but if the script can be made more robust to handle this alternate php setting, that would of course be a good thing.
Back to top
cgrymala
Status: New User - Welcome
Joined: 09 Mar 2009
Posts: 2
Reply Quote
Thank you for the information.

I will keep an eye on my server to see if I can help diagnose the problem further. It seems that the problem has not completely gone away, as I am still getting the error in my apache log occasionally.

I am storing the information gathered by the PHP browser detection script in a database, so I am able to sort of reconcile the timestamps on my apache log with the timestamps in my database. I'll keep an eye out.

Again, thanks for all of your work.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours