Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2005
    Location
    Kelowna, BC Canada
    Posts
    1,075
    Plugin Contributions
    6

    Default [Duplicate] Check if needle actually exists before strstr? $_SERVER['REMOTE_ADDR']

    Hi. I don't know or understand under what circumstance $_SERVER['REMOTE_ADDR'] would not register, but I periodically get this error in my logs:

    PHP Warning: strstr(): Empty needle in /includes/functions/functions_lookups.php on line 712
    It hasn't always been that particular file/line but that's the one it was this time. Every time I've seen it, it is related to $_SERVER['REMOTE_ADDR']

    I wonder if the function(s) should check if $_SERVER['REMOTE_ADDR'] actually exists prior to doing the strstr?

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Check if needle actually exists before strstr? Particularly $_SERVER['REMOTE_ADDR

    Agreed. In v1.5.5 and v1.6.0 it's fixed by ensuring $_SERVER['REMOTE_ADDR'] is never blank, even if the server isn't cooperating by supplying the visitor's IP address.
    .

    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. #3
    Join Date
    Jun 2005
    Location
    Kelowna, BC Canada
    Posts
    1,075
    Plugin Contributions
    6

    Default Re: Check if needle actually exists before strstr? Particularly $_SERVER['REMOTE_ADDR

    Sorry for the duplicate. I should have searched more. Lazy. Bad.

  4. #4
    Join Date
    Apr 2011
    Location
    Espoo, Finland
    Posts
    49
    Plugin Contributions
    0

    Default Re: Check if needle actually exists before strstr? Particularly $_SERVER['REMOTE_ADDR

    Quote Originally Posted by DrByte View Post
    Agreed. In v1.5.5 and v1.6.0 it's fixed by ensuring $_SERVER['REMOTE_ADDR'] is never blank, even if the server isn't cooperating by supplying the visitor's IP address.
    This should probably mean, empty $_SERVER['REMOTE_ADDR'] is being replaced with 'dot' character (in init_sessions.php since 1.5.5), but I'm anyway getting the above mentioned error even using the latest version... (no idea how and why...)

  5. #5
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Check if needle actually exists before strstr? Particularly $_SERVER['REMOTE_ADDR

    Maybe your server configuration is blocking all access to that information.
    .

    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.

  6. #6
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,691
    Plugin Contributions
    9

    Default Re: Check if needle actually exists before strstr? Particularly $_SERVER['REMOTE_ADDR

    hey drB,
    i have a v1.5.5 install and i'm seeing this same error. not all the time, just ran into it twice the other day.

    it is my understanding the browser could be behind a proxy server. and some code similar to this might help (obviously changed to the ZC section in functions_lookup):

    Code:
    <?php
        if(! empty($_SERVER['REMOTE_ADDR']) ){
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    else{
        $ip = empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? '' : $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    in addition, it seems a bit odd to be checking the IP address against the exclude admin address list even IF the site is NOT down for maintenance. or perhaps that is just me.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  7. #7
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Check if needle actually exists before strstr? Particularly $_SERVER['REMOTE_ADDR

    Quote Originally Posted by carlwhat View Post
    hey drB,
    i have a v1.5.5 install and i'm seeing this same error. not all the time, just ran into it twice the other day.

    it is my understanding the browser could be behind a proxy server. and some code similar to this might help (obviously changed to the ZC section in functions_lookup):

    Code:
    <?php
        if(! empty($_SERVER['REMOTE_ADDR']) ){
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    else{
        $ip = empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? '' : $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    in addition, it seems a bit odd to be checking the IP address against the exclude admin address list even IF the site is NOT down for maintenance. or perhaps that is just me.
    I'm struggling to find how it could be blank if your solution is to grab the x_forwarded_for value, since that's already checked ahead of time.
    See: https://github.com/zencart/zencart/b....php#L777-L820
    .

    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.

  8. #8
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,691
    Plugin Contributions
    9

    Default Re: [Duplicate] Check if needle actually exists before strstr? $_SERVER['REMOTE_ADDR'

    the problem is here:

    https://github.com/zencart/zencart/b...okups.php#L747

    i see no checks related to this location.... as the function does not take a variable.....

    although i could be wrong....
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  9. #9
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: [Duplicate] Check if needle actually exists before strstr? $_SERVER['REMOTE_ADDR'

    The variable is overridden by https://github.com/zencart/zencart/b...ns.php#L54-L59

    But, the init_general_funcs loads before init_sessions: https://github.com/zencart/zencart/b....php#L134-L145
    It wouldn't surprise me that there are dependencies that prevent switching the order of these, but feel free to change the 70 to 59 as a test and report your findings.
    .

    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.

 

 

Similar Threads

  1. Replies: 3
    Last Post: 28 Mar 2016, 09:45 PM
  2. v154 PHP Warning: strstr(): Empty needle in
    By frank18 in forum General Questions
    Replies: 18
    Last Post: 1 Feb 2015, 01:05 AM
  3. where do i find $_SERVER['REMOTE_ADDR']
    By Mickyelta in forum General Questions
    Replies: 1
    Last Post: 26 Jan 2012, 01:28 AM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR