Notice : Undefined offset: 1 in counter_get_browser() (ligne 70 in .../sites/all/modules/counter/counter.lib.inc).

This occurs only with Internet Explorer 11 (not tested in older version). No problem with Chrome nor Firefox)

Comments

Philix’s picture

I suggest :
After line 26

  elseif(preg_match('/rv:/i',$user_agent))
  {
    $browser_name = 'Internet Explorer';
    $ub = "rv";
  }

+ After :

$pattern = '#(?<browser>' . join('|', $known ...

Add :

if ($ub == 'rv') $pattern = '#(?<browser>' . join('|', $known) . ')[: ]+(?<browser_version>[0-9.|a-zA-Z.]*)#';

I don't know how to do a patch, sorry
(IE never do like others ... :( )

waluyo.umam’s picture

I have the same problem in Internet Explorer 11, the red warning shown.
Your code suggestion fixed the problem. I hope this can be included in the next release.

Thanks a lot.

jmuzz’s picture

Status: Active » Needs review
StatusFileSize
new961 bytes

This is Philix's recommendations with some changes to the last part which shouldn't change how it works.

Valera Tumash’s picture

StatusFileSize
new2.81 KB

1. Recently in logs I have found few weird sessions from clients without HTTP_USER_AGENT set in $_SERVER. So for this use case I believe it is reasonable to change 4 line from
$user_agent = $_SERVER['HTTP_USER_AGENT'];
to
$user_agent = array_key_exists('HTTP_USER_AGENT', $_SERVER) ? $_SERVER['HTTP_USER_AGENT'] : 'Unknown';

2. There were few sessions with following HTTP_USER_AGENT:
'Mozilla/4.0 (compatible;HostTracker/2.0;+http://www.host-tracker.com/)'
'Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)'

So I reckon there will always be a case when we got same Undefined offset: 1 in counter_get_browser() notice.

In order to eliminate this I changed the condition to:

  if ( $ub != 'Unknown' ) {
    if ($i != 1) {
      //we will have two since we are not using 'other' argument yet
      //see if browser_version is before or after the name
      if (strripos($user_agent,"browser_version") < strripos($user_agent,$ub)){
        $browser_version= $matches['browser_version'][0];
      }
      else {
        $browser_version= $matches['browser_version'][1];
      }
    }
    else {
    $browser_version= $matches['browser_version'][0];
    }
  }

I have attached a patch file combined with the previous patch in this issue.

modulusng’s picture

Notice: Undefined offset: 1 in counter_get_browser()

Notice: Undefined offset: 1 in counter_get_browser() (line 76 of /.../sites/all/modules/counter/counter.lib.inc). This error ocurs only with Internet Explorer 11 but not with older versions. The error is not associated with Chrome and Firefox browsers.

Follow the following steps: Navigate to counter.lib.inc through /.../sites/all/modules/counter/counter.lib.inc and open counter.lib.inc on your editor as to edit the file as follows:

After this:

{
$browser_name = 'Internet Explorer';
$ub = "IE";
}

Add this:

elseif(preg_match('/rv:/i',$user_agent))
{
$browser_name = 'Internet Explorer';
$ub = "rv";
}

After this:

// finally get the correct browser_version number
$known = array('browser_version', $ub, 'other');
$pattern = '#(?' . join('|', $known) .
')+(?*)#';

Add this:

if ($ub == 'rv') $pattern = '#(?' . join('|', $known) . ')+(?*)#';

The above procedure gets the issue resolved. For more info, go to: https://www.myniceitems.com/content/notice-undefined-offset-1-counterget...

firfin’s picture

#5 did not work for me. Getting errors:
Warning: preg_match_all() [function.preg-match-all]: Compilation failed: unrecognized character after (? or )?- at offset 2 in counter_get_browser() (line 65 of ../counter.lib.inc)

Trying out #3 now.

plato1123’s picture

I notice there are multiple errors in the current release, any chance we can get a new roll out with some of the patches rolled into it? Thanks!!