• Resolved bseddon

    (@bseddon)


    You may be lucky enough only to have visitors that present good, well formed requests. Sadly, we are not.

    If a request is received from a browser (or something more sinister) that does not include a browser agent WP Statistics causes notices to fill up my log complaining about a missing index ‘HTTP_USER_AGENT’ affecting lines 74, 106 and 107 of hits.class.php.

    I’m not sure what it the correct way to address this issue. My solution is to change part of the constructor in the way shown below to set the exclusion_match and add a reason ‘no_agent’ when there is no agent available (isset($_SERVER[‘HTTP_USER_AGENT’]) === FALSE). If nothing else it at least suppresses the notices.

    // If we're a crawler as per browscap, exclude us, otherwise double check based on the WP Statistics robot list.
    if( $crawler == true ) {
    	$this->exclusion_match = TRUE;
    	$this->exclusion_reason = "browscap";
    }
    else {
    
    	if (isset($_SERVER['HTTP_USER_AGENT']))
    	{
    		// Pull the robots from the database.
    		$robots = explode( "\n", $this->get_option('robotlist') );
    
    		// Check to see if we match any of the robots.
    		foreach($robots as $robot) {
    			$robot = trim($robot);
    
    			// If the match case is less than 4 characters long, it might match too much so don't execute it.
    			if(strlen($robot) > 3) {
    				if(isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], $robot) !== FALSE) {
    					$this->exclusion_match = TRUE;
    					$this->exclusion_reason = "robot";
    					break;
    				}
    			}
    		}
    	}
    	else
    	{
    		$this->exclusion_match = TRUE;
    		$this->exclusion_reason = "no_agent";
    	}
    }

    https://www.ads-software.com/plugins/wp-statistics/

Viewing 1 replies (of 1 total)
  • Plugin Contributor Greg Ross

    (@gregross)

    The better way is to use another variable that get’s set to an empty string if no HTTP_USER_AGENT is passed.

    A fix will be in the next release.

Viewing 1 replies (of 1 total)
  • The topic ‘Problem with empty agent string’ is closed to new replies.