Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19
  1. #11
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,378
    Plugin Contributions
    9

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

    Searching the forums I found another thread covering the same issue with a ZC 1.5.3 version:

    https://www.zen-cart.com/showthread....iles-yesterday

  2. #12
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

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

    Are you able to trigger it on-demand? That would be helpful for proper resolution.

    Could possibly be caused by IP address spoofing, or malicious manipulation by the visitor to mask their address such that the $_SERVER array doesn't have a value there, or perhaps crafty DNS registration which reports invalid data.
    Or a weird proxy server configuraiton if you're using one.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #13
    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 DrByte View Post
    Are you able to trigger it on-demand? That would be helpful for proper resolution.

    Could possibly be caused by IP address spoofing, or malicious manipulation by the visitor to mask their address such that the $_SERVER array doesn't have a value there, or perhaps crafty DNS registration which reports invalid data.
    Or a weird proxy server configuraiton if you're using one.
    Thanks

    Can't trigger it on demand but found the corresponding server log entry for this error:


    [28-Jan-2015 19:55:58 UTC] PHP Warning: strstr(): Empty needle in /home/sunnsand/public_html/includes/functions/functions_lookups.php on line 712
    Log entry (adusted for server/UTC time difference):


    78.129.250.17 - - [29/Jan/2015:06:55:58 +1100] "GET /index.php?main_page=index&cPath=13_15_23 HTTP/1.1" 200 11389 "-" "Mozilla/5.0 (compatible; aiHitBot/2.9; +http://www.aihitdata.com/about)"
    As far as I know my server is not using a weird proxy server configuration.


    I am frequently checking the logs of all (virtual) servers and have never seen this particular error before with any of the hosted ZC sites - this is a first in 5 years with the same host.


    And - all sites are residing on the same physical server.

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

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

    Quote Originally Posted by frank18 View Post
    As far as I know my server is not using a weird proxy server configuration.
    Perhaps not, but the issue could arise if the client is using a proxy and it is their proxy that is mangling things.

    Quote Originally Posted by frank18 View Post
    I am frequently checking the logs of all (virtual) servers and have never seen this particular error before with any of the hosted ZC sites - this is a first in 5 years with the same host.
    I have seen it before, but not enough for me to consider it worth worrying about.

    I've just been doing a bit of Googling though and found that others have overcome the problem by adding a function to retrieve the IP address rather than simply relying on the $_SERVER['REMOTE_ADDR'] variable.

    https://gist.github.com/cballou/2201933

    It shouldn't be difficult to incorporate into ZenCart if you are really that concerned about it.

    FYI, the $_SERVER['REMOTE_ADDR'] variable has never been 100% reliable, because even if the client is coming in from a correctly configured proxy the IP address returned will be for the Proxy server rather than the end user (To get the end users IP address in this case you'd need to use the $_SERVER['HTTP_X_FORWARDED_FOR'] variable).
    If the proxy has been configured to use invalid data for its own IP address there isn't much you can do about it other than to retrieve the data from elsewhere (as per the function in the link above).

    Cheers
    RodG

  5. #15
    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

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

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

    we've been referring to it as an error, it is actually a warning, suppressing the warning with @ should be viable

  7. #17
    Join Date
    Aug 2009
    Location
    North Idaho, USA
    Posts
    2,008
    Plugin Contributions
    1

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

    Quote Originally Posted by frank18 View Post
    Searching the forums I found another thread covering the same issue with a ZC 1.5.3 version:

    https://www.zen-cart.com/showthread....iles-yesterday
    FWIW, I have not seen the issue since using lat9's suggestion.
    Rick
    RixStix (dot) com
    aka: ChainWeavers (dot) com

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

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

    That's good, FWIW that is what I suggested in post #2

  9. #19
    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
    we've been referring to it as an error, it is actually a warning, suppressing the warning with @ should be viable

    Point taken, thanks


    Quote Originally Posted by RixStix View Post
    FWIW, I have not seen the issue since using lat9's suggestion.

    Yep, implemented that suggestion on all sites


    Thanks to all of you guys for your input and suggestions, much appreciated.


    Cheers / Frank

 

 
Page 2 of 2 FirstFirst 12

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