• Resolved Frank B.

    (@frankbiganski)


    Hi,

    I’ve been using your plugin for several years without an issues but after switching to Cloudways hosting, I have to clear the plugin’s cache every 2-3 days as the plugin is perceiving a country code of ZZ 127.0.0.1 as an issue of some sort. I got locked out of my site and had to ftp to the backend to delete your plugin. The ZZ country code and 127.0.0.1 is of course my hosting provider’s servers in New York.

    I want to continue using your plugin because 95% of my visitors are from the US (real estate website) so I block Russia and about a dozen other countries that always try to access my website. But I had to delete the plugin can’t because of the need to clear the cache thing every 2-3 days.

    I can email you screenshots of what I was seeing.

    Thanks!

    Frank
    https://mrtownhome.net

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author tokkonopapa

    (@tokkonopapa)

    Hi Frank,

    Thank you for your using my plugin so long time!

    I googled about Cloudways and found “$_SERVER[‘REMOTE_ADDR’] returns 127.0.0.1” at Stack Overflow. Someone said:

    I had this problem when using nginx as a load balancer.

    And also I found another comment in this page:

    This common problem I had noticed on Cloudways web hosting.

    So I think we should find a way to identify the client IP address on Cloudways server. The both code snippets in the above pages might be wrong from the security point of view. I don’t implement those kind of code by default because attacker can easily declare false information to avoid blocking by country.

    And unfortunately, I can not find any help in Cloudways support about how to get client IP address. So I assume $_SERVER['HTTP_X_FORWARDED_FOR'] is our right choice.

    function my_replace_ip( $ip ) {
        if ( '127.0.0.1' === $_SERVER['REMOTE_ADDR'] && ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
            $tmp = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] );
            $tmp = trim( $tmp[0] );
            if ( filter_var( $tmp, FILTER_VALIDATE_IP ) ) {
                $ip = $tmp;
            }
        }
    
        return $ip;
    }
    add_filter( 'ip-geo-block-ip-addr', 'my_replace_ip' );

    You can put the above code into functions.php in your theme, or drop-in.php in geolocation database directory when you select ““mu-plugins” (ip-geo-block-mu.php) as validation timing.

    Also please refer to ip-geo-block-ip-addr.

    If the above code could not resolve your issue, please let me know in this thread. I should provide you another snippet.

    Good luck!

    Thread Starter Frank B.

    (@frankbiganski)

    Thanks much, and sorry for that other/double post. I’ll give this a try this weekend (which I have a clearer mind, no work, etc. and will let you know how it goes.

    Frank

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Need to Clear Cache Every 2-3 Days’ is closed to new replies.