Title: inc/functions/ip_in_range.php throws error when exploded array lacks 2nd val
Last modified: August 21, 2016

---

# inc/functions/ip_in_range.php throws error when exploded array lacks 2nd val

 *  [sgpark](https://wordpress.org/support/users/sgpark/)
 * (@sgpark)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/incfunctionsip_in_rangephp-throws-error-when-exploded-array-lacks-2nd-val/)
 * I had to modify this
 *     ```
       $pieces = explode ("/", $range_ip, 2);
           $left_piece = $pieces[0];
           $right_piece = $pieces[1];
   
       // Extract out the main IP pieces
           $ip_pieces = explode("::", $left_piece, 2);
           $main_ip_piece = $ip_pieces[0];
           $last_ip_piece = $ip_pieces[1];
       ```
   
 * to something like this
 *     ```
       $pieces = explode ("/", $range_ip, 2);
       	if (count($pieces) > 0)
           $left_piece = $pieces[0];
       	if (count($pieces) > 1)
           $right_piece = $pieces[1];
   
       // Extract out the main IP pieces
           $ip_pieces = explode("::", $left_piece, 2);
       	if (count($ip_pieces) > 0)
           $main_ip_piece = $ip_pieces[0];
       	if (count($ip_pieces) > 1)
           $last_ip_piece = $ip_pieces[1];
       ```
   
 * and this
    `if (trim($last_ip_piece) != "") {`
 * to something like this
    `if (isset($last_ip_piece) && trim($last_ip_piece) !=""){`
 * in two of the functions.
 * [https://wordpress.org/plugins/w3-total-cache/](https://wordpress.org/plugins/w3-total-cache/)

 The topic ‘inc/functions/ip_in_range.php throws error when exploded array lacks
2nd val’ is closed to new replies.

 * ![](https://ps.w.org/w3-total-cache/assets/icon-256x256.png?rev=1041806)
 * [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/w3-total-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/w3-total-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/w3-total-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/w3-total-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/w3-total-cache/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [sgpark](https://wordpress.org/support/users/sgpark/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/incfunctionsip_in_rangephp-throws-error-when-exploded-array-lacks-2nd-val/)
 * Status: not resolved