Skip to content

Commit

Permalink
Fix PHP Notice Undefined offset
Browse files Browse the repository at this point in the history
  • Loading branch information
dregad committed Jun 18, 2014
1 parent 93e1135 commit 837541e
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions browser_check.php
Expand Up @@ -8,7 +8,6 @@
*/
function getBrowser() {
$u_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
$version = '';

# First get the platform
if( preg_match( '/linux/', $u_agent ) ) {
Expand Down Expand Up @@ -47,26 +46,27 @@ function getBrowser() {
$known = array( 'version', $ub, 'other' );
$pattern = '#(?<browser>' . join( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
if( !preg_match_all( $pattern, $u_agent, $matches ) ) {
# we have no matching number just continue
}

# see how many we have
$i = count( $matches['browser'] );
if( $i != 1 ) {
# we will have two since we are not using 'other' argument yet
# see if version is before or after the name
if( strrpos( $u_agent, 'version' ) < strrpos( $u_agent, $ub ) ) {
$version = $matches['version'][0];
# we have no matching number
$version = '?';
} else {
# see how many we have
$i = count( $matches['browser'] );
if( $i >= 1 ) {
# we will have two since we are not using 'other' argument yet
# see if version is before or after the name
if( strrpos( $u_agent, 'version' ) < strrpos( $u_agent, $ub ) ) {
$version = $matches['version'][0];
} else {
$version = $matches['version'][1];
}
} else {
$version = $matches['version'][1];
$version = $matches['version'][0];
}
} else {
$version = $matches['version'][0];
}

# check if we have a number
if( $version == '' ) {
$version = '?';
# check if we have a number
if( $version == '' ) {
$version = '?';
}
}

return array(
Expand Down

0 comments on commit 837541e

Please sign in to comment.