• Resolved advantechmsp

    (@advantechmsp)


    The IP address is invalid for hosts with certain caching systems setup or a CDN. Can we get an option to use “X-Real-IP HTTP header” or something similar?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Michael Beckwith

    (@tw2113)

    The BenchPresser

    We have this filter available that you could tap into:

    update_user_meta( $user_id, '_bprwg_ip_address', apply_filters( '_bprwg_ip_address', $_SERVER['REMOTE_ADDR'] ) );
    

    Something like this would work fine:

    function advantechmsp_ip_address( $ip_address ) {
        // Return the "X-Real-IP HTTP header" value here.
    }
    add_filter( '_bprwg_ip_address', 'advantechmsp_ip_address' );
    

    That would override our default value.

    Thread Starter advantechmsp

    (@advantechmsp)

    I am not sure how to use this. Tried it as a php snippet (basically a custom function.php) but it still returns the server’s address instead of my own.

    I really do appreciate your help BTW ??

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    What code are you using exactly?

    Thread Starter advantechmsp

    (@advantechmsp)

    function advantechmsp_ip_address( $ip_address ) {
        update_user_meta( $user_id, '_bprwg_ip_address', apply_filters( '_bprwg_ip_address', $_SERVER['REMOTE_ADDR'] ) );
    }
    add_filter( '_bprwg_ip_address', 'advantechmsp_ip_address' );
    

    As a non-programmer i tend to just bash things together until it works ??

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Doing a bit too much there.

    Just for quick example sake, since I don’t know offhand what global potentially provides the X-Real-IP header you’re wanting:

    function advantechmsp_ip_address( $ip_address ) {
        return $_SERVER['X-Real-IP'];
    }
    add_filter( '_bprwg_ip_address', 'advantechmsp_ip_address' );
    

    All you need to do for this.

    the $ip_address variable will hold the original value we intend to save, provided by $_SERVER['REMOTE_ADDR']. However, you can return something completely different and THAT value will be saved instead. You could return “Pennywise’s Home” and that would end up being saved as the user meta. Sorry, watched Chapter 2 tonight :D.

    So, back on topic, whatever provides the IP you’re intending to use, is what should be returned.

    That said, since we only use the IP address for some rudimentary location indication, during the moderation process, and delete the saved value after they’ve been approved, not sure how useful this is actually going to be to you. We added the deletion of the meta for GDPR purposes.

    Thread Starter advantechmsp

    (@advantechmsp)

    The use is simply to ban trolls. I’ll give it a shot in a minute.

    How was CH. 2? Will be going to see it next week.

    Thread Starter advantechmsp

    (@advantechmsp)

    Hrm, still the wrong IP address. I wonder if the snippet is running properly. I’ll keep whacking at it.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    best guess i have is that it’s not running at all.

    Thread Starter advantechmsp

    (@advantechmsp)

    Hrm, still can’t get it to stick. other snippets work so not sure. Where in the plugin is the IP address called so I can attempt to edit it there (not a permanent solution but a good test).
    If you want to take a look it is here: hellsbasement.info

    • This reply was modified 5 years, 2 months ago by advantechmsp.
    Thread Starter advantechmsp

    (@advantechmsp)

    Ok, no worries. The issues was a misconfigured nginx on the backend. Our host fixed it ??

    Thread Starter advantechmsp

    (@advantechmsp)

    resolved

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Awesome to hear you got this worked out in the end, I was running out of ideas ??

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Wrong IP address detected’ is closed to new replies.