Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,378
    Plugin Contributions
    9

    Default PHP Warning: strstr(): Empty needle in

    Just checked the logs of a client site - ZC 1.5.4 - and found 32 identical (...except for the time) entries in the logs folder - all in the space of about 2 minutes:

    [28-Jan-2015 19:56:38 UTC] PHP Warning: strstr(): Empty needle in /home/[account_name]/public_html/includes/functions/functions_lookups.php on line 712

    That line reads

    PHP Code:
    case (strstr(EXCLUDE_ADMIN_IP_FOR_MAINTENANCE$_SERVER['REMOTE_ADDR'])): 
    Checked the admin logs for that date - nothing extraordinary.... site was not down for maintenance.

    Never had this error previously. Could anyone shed a light on this please....

    Cheers / Frank
    Last edited by frank18; 31 Jan 2015 at 08:58 AM.

  2. #2
    Join Date
    Dec 2014
    Location
    SE TX
    Posts
    32
    Plugin Contributions
    0

    Default Re: PHP Warning: strstr(): Empty needle in

    $_SERVER['REMOTE_ADDR'] can be empty, which causes the error

    I think you can suppress the error with @
    Code:
    case (@strstr(EXCLUDE_ADMIN_IP_FOR_MAINTENANCE, $_SERVER['REMOTE_ADDR'])):
    or clarify the case condition
    Code:
    case (!empty($_SERVER['REMOTE_ADDR'])&&strstr(EXCLUDE_ADMIN_IP_FOR_MAINTENANCE, $_SERVER['REMOTE_ADDR'])):

  3. #3
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,378
    Plugin Contributions
    9

    Default Re: PHP Warning: strstr(): Empty needle in

    Quote Originally Posted by SignTorch View Post
    $_SERVER['REMOTE_ADDR'] can be empty, which causes the error

    I think you can suppress the error with @
    Code:
    case (@strstr(EXCLUDE_ADMIN_IP_FOR_MAINTENANCE, $_SERVER['REMOTE_ADDR'])):
    or clarify the case condition
    Code:
    case (!empty($_SERVER['REMOTE_ADDR'])&&strstr(EXCLUDE_ADMIN_IP_FOR_MAINTENANCE, $_SERVER['REMOTE_ADDR'])):
    Thanks - but suppressing the error is not much good to me, I would like to know the reason for this error.

  4. #4
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,845
    Plugin Contributions
    25

    Default Re: PHP Warning: strstr(): Empty needle in

    Quote Originally Posted by frank18 View Post
    Thanks - but suppressing the error is not much good to me, I would like to know the reason for this error.
    You probably have no value set for you admin ip under configuration->maintenance

  5. #5
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,378
    Plugin Contributions
    9

    Default Re: PHP Warning: strstr(): Empty needle in

    Quote Originally Posted by Design75 View Post
    You probably have no value set for you admin ip under configuration->maintenance
    Yes, an IP is set, the field is not empty

  6. #6
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: PHP Warning: strstr(): Empty needle in

    Quote Originally Posted by Design75 View Post
    You probably have no value set for you admin ip under configuration->maintenance
    Nah, it wouldn't be that. The error message is "PHP Warning: strstr(): Empty needle", which means that it's the $_SERVER['REMOTE_ADDR'] variable being set.

    Why it's not being set is something I can't answer, but as SignTorch suggested, suppressing the error is probably the easiest 'fix'.

    Cheers
    RodG

  7. #7
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: PHP Warning: strstr(): Empty needle in

    Addendum:

    That should have read:

    It's the$_SERVER['REMOTE_ADDR'] variable NOT being set.

    Cheers
    RodG

    ps. Does anyone else experience lockups when trying to edit a post or is it just me? Doesn't happen all the time, but often enough that its become a real headache.

  8. #8
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,845
    Plugin Contributions
    25

    Default Re: PHP Warning: strstr(): Empty needle in

    Quote Originally Posted by RodG View Post
    Nah, it wouldn't be that. The error message is "PHP Warning: strstr(): Empty needle", which means that it's the $_SERVER['REMOTE_ADDR'] variable being set.
    Duh , I guess i needed more coffee this morning

  9. #9
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,378
    Plugin Contributions
    9

    Default Re: PHP Warning: strstr(): Empty needle in

    Quote Originally Posted by RodG View Post
    Why it's not being set is something I can't answer, but as SignTorch suggested, suppressing the error is probably the easiest 'fix'.

    Cheers
    RodG
    Yeah, I guess so - BUT the question still remains: why is the error happening, is it a bug in the coding -- or what??

  10. #10
    Join Date
    Dec 2014
    Location
    SE TX
    Posts
    32
    Plugin Contributions
    0

    Default Re: PHP Warning: strstr(): Empty needle in

    Quote Originally Posted by frank18 View Post
    Thanks - but suppressing the error is not much good to me, I would like to know the reason for this error.
    the reason is because the variable $_SERVER['REMOTE_ADDR'] can be empty, when it is empty the function strstr() throws the error, because it can't have an empty needle parameter

    my 2nd suggestion should prevent the error because it doesn't run strstr() when $_SERVER['REMOTE_ADDR'] is empty

    you could try additional ways to get the visitor's ip address, but nothing is 100% bullet proof, and in this case only administrator IP addresses are relevant, when the store is in maintenance mode, it is not necessary to resolve the IP address of all visitors all the time

    zen cart does have a function to check several other environment variables for an IP address

    admin/includes/functions/general.php

    Code:
    /**
     * Get and sanitize the current IP address, detecting past proxies where possible
     * @return IP address
     */
    function zen_get_ip_address() {
      if (isset($_SERVER)) {
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
          $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
          $ip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (isset($_SERVER['HTTP_X_FORWARDED'])) {
          $ip = $_SERVER['HTTP_X_FORWARDED'];
        } elseif (isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) {
          $ip = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
        } elseif (isset($_SERVER['HTTP_FORWARDED_FOR'])) {
          $ip = $_SERVER['HTTP_FORWARDED_FOR'];
        } elseif (isset($_SERVER['HTTP_FORWARDED'])) {
          $ip = $_SERVER['HTTP_FORWARDED'];
        } else {
          $ip = $_SERVER['REMOTE_ADDR'];
        }
      } else {
        if (getenv('HTTP_X_FORWARDED_FOR')) {
          $ip = getenv('HTTP_X_FORWARDED_FOR');
        } elseif (getenv('HTTP_CLIENT_IP')) {
          $ip = getenv('HTTP_CLIENT_IP');
        } else {
          $ip = getenv('REMOTE_ADDR');
        }
      }
    
      return $ip;
    }
    to prevent the error you would still have to avoid running strstr() on an empty string

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 8
    Last Post: 2 Apr 2017, 02:55 PM
  2. Replies: 20
    Last Post: 7 Dec 2014, 11:29 AM
  3. Replies: 0
    Last Post: 27 Sep 2012, 11:57 PM
  4. v139h PHP Warning: strstr() Empty delimiter HELP
    By Enpeek in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 28 Apr 2012, 09:43 AM
  5. v139h PHP Warning: strstr() Empty delimiter HELP
    By Enpeek in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 18 Apr 2012, 02:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg