Bug in NT 5.1 Detection
gabboflabbo
Status: New User - Welcome
Joined: 15 Mar 2004
Posts: 1
Reply Quote
Hi, thanks for the great browser detection php script. Small and quick =)

For file browser_detection_php_ar.txt, Line 350, Col 59.

The bracket is placed wrong for the strstr call:

this :

if ( strstr( $browser_string, 'nt 5.1' || strstr( $browser_string, 'xp' )) )// windows xp

should be:

if ( strstr( $browser_string, 'nt 5.1') || strstr( $browser_string, 'xp' ) )// windows xp

thanks again,

-- Gabbo
Back to top
thanks for spotting that.
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 3753
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
Gabboflabbo, thanks for catching that, that is now corrected, as of:
Version 4.2.8

That os version detector leaves something to be desired I have to say, it's the weakest part of the script, it works, but that's about it.

Sorry about the size of the script, it's grown a bit large :) , but you can optimize its performance a bit by doing the following:

:: Code ::

// call it in a function, but first create some static variables to hold
//the full array contents, also whatever else you might  need
// repeatedly in your page
function get_browser_info( $feature )
{
static $a_browser_data, $browser, $browser_number, $os;

// then load the include, pack the full information into the
//static variable

if ( !$a_browser_data )
{
   include_once('programs/browser_detection.inc');
   $a_browser_data = browser_detection('full');
// pack the moz_version data into the static array
// if it's a gecko browser, otherwise do nothing
   ( $a_browser_data[0] == 'moz' ) ? $a_browser_data[] = browser_detection('moz_version') : '';
   $browser = $a_browser_data[0];
   $browser_number = $a_browser_data[1];
   $os = $a_browser_data[5];
}
// then just return what you need by the $feature parameter, for
// example
if ($feature == 'full')
{
return $a_browser_data;
}
elseif ($feature == 'browser')
{
return $browser;
}
// and so on, that will save a bit of server load, especially on busy sites
}


This means that the include is called only once, and the browser detector runs only once, and all your browser data is available to you. However, the script is already optimized to only run through once, and packs the static variables in it, so unless speed is really important, the above process isn't actually necessary.
Back to top
PHP Browser Detection script: can't see Linux
englishextra
Status: Interested
Joined: 25 Dec 2007
Posts: 11
Location: Moscow, Russian Federation
Reply Quote
Hello colleagues! Great script. Your backlink as you wished to is placed here: englishextra.org.ua/index.php?page_id=about_webmaster

However, I encountered a problem with Linux OS. For intstance, this user-agent string doesn't get detected in terms of 'os' and 'os_version'.

Please advise upon this matter.

The string:

Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.8.1.8) Gecko/20071019 Fedora/2.0.0.8-1.fc7 Firefox/2.0.0.8
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 3753
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
Seems to work fine. Running your user agent string, I get this using the 'your computer' feature:

:: Quote ::
Your Computer
Operating System:

Linux
Distro: Fedora
Current Browser / UA:

Mozilla/ Firefox
ProductSub: Not Available
RV version: 1.8.1.8
XHTML support: Yes

Note, I added fedora into the distro array, but it was working fine before too. The OS and distro come from os and os_version returns, so you must be doing something slightly off I think.
Back to top
englishextra
Status: Interested
Joined: 25 Dec 2007
Posts: 11
Location: Moscow, Russian Federation
Reply Quote
:: techAdmin wrote ::
I added fedora into the distro array, but it was working fine before too. The OS and distro come from os and os_version returns, so you must be doing something slightly off I think.


Oh yes. I added FEDORA too to the array

I recieve Windows and its version OK. I get FREEBSD and LIBWWW-Perl and MAC successfully.

What I wonder is that 'freebsd' is in the same array $a_os as 'fedora' (added by myself) to the $a_linux which is included into $a_os

FREEBSD gets recognised FEDORA doesn't. And By the way, analysing server error_log I found out that this produces an error:

:: Code ::
$a_os = array( 'beos', 'os2', 'amiga', 'webtv', 'mac', 'nt', 'win', $a_unix, $a_linux );


so I ended up with this:
:: Code ::
   // only sometimes will you get a linux distro to id itself...
   $a_linux = array( 'kanotix', 'ubuntu', 'mepis', 'debian', 'suse', 'redhat', 'slackware', 'mandrake', 'gentoo', 'linux', 'fedora' );
   $a_linux_process = array ( 'i386', 'i586', 'i686' );// not use currently
   // note, order of os very important in os array, you will get failed ids if changed
   //$a_os = array( 'beos', 'os2', 'amiga', 'webtv', 'mac', 'nt', 'win', $a_unix, $a_linux );
   $a_os = array( 'beos', 'os2', 'amiga', 'webtv', 'mac', 'nt', 'win', 'unixware', 'solaris', 'sunos', 'sun4', 'sun5', 'suni86', 'sun',
      'freebsd', 'openbsd', 'bsd' , 'irix5', 'irix6', 'irix', 'hpux9', 'hpux10', 'hpux11', 'hpux', 'hp-ux',
      'aix1', 'aix2', 'aix3', 'aix4', 'aix5', 'aix', 'sco', 'unixware', 'mpras', 'reliant',
      'dec', 'sinix', 'unix', 'kanotix', 'ubuntu', 'mepis', 'debian', 'suse', 'redhat', 'slackware', 'mandrake', 'gentoo', 'linux', 'fedora');//shimansky


family name comment means changes done by myself
Thanks for your support

You might use this test table: englishextra.org.ua/browser_detection.php (I used it to see what happens if I come from Win XP:
browser moz
number 1.8
type bro
os nt
os_number 5.1

and from fedora 7:
browser moz
number 1.8
type bro
os
os_number
)

Here is the library I use with changes, that commented //shimansky

englishextra.org.ua/browser_detection.txt

What I changed:
Declared some variables (empty)
preplaces array variables with array values for a_unix and a_linux
cause this produced an error in server log
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 3753
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
you've made a mistake, but I can't support going through your changed code, only the original, which is working fine. You'll need to debug your mistakes yourself, I can't spend my time for you, sorry.

Freebsd should have been in the unix array, not the linux array.
Back to top
englishextra
Status: Interested
Joined: 25 Dec 2007
Posts: 11
Location: Moscow, Russian Federation
Reply Quote
All right sorry for bothering/ Can I place the oroginal code, see what happens with fedora detection and server logs and then come back to you with server error_log extracts?
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 3753
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
Just tested to confirm:

:: Quote ::
Unix
Version: FREEBSD
Current Browser / UA:

Mozilla/ Firefox 2.0.0.11
ProductSub: 20071223
RV version: 1.8.1.11
XHTML support: Yes


works fine in running script, here for example: tech/downloads/browser_detection.php

So you'll need to debug your stuff and figure out what you broke.

There is however a small bug in the fedora detection, it fails to get the firefox version number, just the rv number, I'll have to take a look at that and see why.

Version 4.9.14 has slightly updated os lists for linux, and cleaned up a bit those arrays.
Back to top
Bug fix
Baaves
Status: New User - Welcome
Joined: 23 Sep 2009
Posts: 1
Reply Quote
Great script! Love it! :)

I have noticed though that some notices are showing in the latest versions of PHP, when using the full browser detection script.

The notices that are showing up, are informing about the use of a deprecated function: ereg(). In order to solve this, I have replaced the ereg() calls by preg_match() calls. There are exactly 2 lines where the source code should be updated:

Line 370:
:: Code ::
ereg('[^0-9][a-z]*-*\ *[a-z]*\ *[a-z]*', $s_browser, $r );


Could be replaced by:
:: Code ::
preg_match('/[^0-9][a-z]*-*\ *[a-z]*\ *[a-z]*/', $s_browser, $r );


Line 389:
:: Code ::
if ( ereg('[0-9]*\.*[0-9]*', $version_number, $m ) )


Could be replaced by
:: Code ::
if ( preg_match('/[0-9]*\.*[0-9]*/', $version_number, $m ) )


Keep up the great work! :)
Baaves
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 3753
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
wow, code patches, line numbers, and clear reason for change! What's the world coming to?

See 4.11.1 for updated and patched, thanks for noting this subtle issue, it's not one I see on any of my sites or servers, but it's great to remove legacy/deprecated features anyway.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours