Title: Udefined index and offset
Last modified: August 21, 2016

---

# Udefined index and offset

 *  Resolved [Per Alm](https://wordpress.org/support/users/per-alm/)
 * (@per-alm)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/udefined-index-and-offset/)
 * **I GOT:**
    Undefined index: HTTP_REFERER …./wp-content/plugins/wp-statistics/
   includes/classes/statistics.class.php Row: 118 Undefined offset: 1 …./wp-content/
   plugins/wp-statistics/includes/classes/hits.class.php Row: 124 Undefined offset:
   1 …./wp-content/plugins/wp-statistics/includes/classes/hits.class.php Row: 125
 * **PROPOSED SOLUTIONS:**
 * statistics.class.php Row 111:
 * if( isset($_SERVER[‘HTTP_REFERER’]) ) { //**NEW LINE**
    if( $default_referr ){
   if( !esc_sql(strip_tags($_SERVER[‘HTTP_REFERER’])) ) { return get_bloginfo(‘url’);}
   else { return esc_sql(strip_tags($_SERVER[‘HTTP_REFERER’])); } } else { return
   esc_sql(strip_tags($_SERVER[‘HTTP_REFERER’])); } } //**NEW LINE**
 * hits.class.php Row 124:
 * if( isset($ip_arr[1]) ) { //**NEW LINE**
    $x = ip2long($ip_arr[1]); $mask = long2ip(
   $x) == $ip_arr[1] ? $x : 0xffffffff << (32 – $ip_arr[1]); $ip_long = ip2long(
   $ip);
 *  // echo “>”.$ip_arr[1].”> “.decbin($mask).”\n”;
    return ($ip_long & $mask) =
   = ($network_long & $mask); } //**NEW LINE**
 * [https://wordpress.org/plugins/wp-statistics/](https://wordpress.org/plugins/wp-statistics/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Contributor [Greg Ross](https://wordpress.org/support/users/gregross/)
 * (@gregross)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/udefined-index-and-offset/#post-4648640)
 * The first function is a little bit inelegent, this is probably better:
 *     ```
       $referr = '';
   
       if( isset($_SERVER['HTTP_REFERER']) ) { $referr = $_SERVER['HTTP_REFERER']; }
       if( $default_referr ) { $referr = $default_referr; }
   
       $referr = esc_sql(strip_tags($referr) );
   
       if( !$referr ) { $referr = get_bloginfo('url'); }
   
       return $referr;
       ```
   
 * The second one should instead just assume a 0 mask:
 *     ```
       $ip_arr = explode('/', $network);
   
       if( !isset( $ip_arr[1] ) ) { $ip_arr[1] = 0; }
   
       $network_long = ip2long($ip_arr[0]);
       ```
   
 *  Plugin Contributor [Greg Ross](https://wordpress.org/support/users/gregross/)
 * (@gregross)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/udefined-index-and-offset/#post-4648876)
 * Closing topic.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Udefined index and offset’ is closed to new replies.

 * ![](https://ps.w.org/wp-statistics/assets/icon.svg?rev=3081064)
 * [WP Statistics – Simple, privacy-friendly Google Analytics alternative](https://wordpress.org/plugins/wp-statistics/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-statistics/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-statistics/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-statistics/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-statistics/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-statistics/reviews/)

## Tags

 * [undefined index](https://wordpress.org/support/topic-tag/undefined-index/)
 * [undefined offset](https://wordpress.org/support/topic-tag/undefined-offset/)

 * 2 replies
 * 2 participants
 * Last reply from: [Greg Ross](https://wordpress.org/support/users/gregross/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/udefined-index-and-offset/#post-4648876)
 * Status: resolved