Recently I’ve been doing some updates to the Fraud Monitor extension for Easy Digital Downloads which helps store owners avoid costly charge-back fees from fraudulent credit card purchases. The most recent feature is one that verifies the IP address that is downloading the files is in a country not on the blacklist.

When writing this feature I found out that most local hosts (used in development) use either 127.0.0.1 or ::1 as the ‘IP Address’ of the local computer making a request. Even in setups with vagrant and other situations a private IP is what is reveled as the IP making the purchase. The problem is, these IPs are not query-able in tools that do GeoIP lookups, to determine which country, state, or even city an IP address is registered in. This is a key feature of a fraud detection tool. For this reason, I felt it necessary to write a little plugin that does a lookup of my externally facing IP (assigned by my Internet Service Provider) and use IT as my $_SERVER['REMOTE_ADDR'].

By doing this, now when I make purchase in Easy Digital Downloads (in my local development environment), my IP address will be one that can be run through Geo IP lookups and WHOIS requests, allowing me to develop tools based on these types of services.

I’ve built a little single file plugin for WordPress to use on your local host during development that checks the external IP once per hour to use it instead of your ‘local ip’.

Below, you can download a single file plugin to install on your local WordPress site, allowing you to have the same freedoms to do GeoIP lookups in your WordPress projects.

The code looks like this:

<?php
/**
 * Plugin Name: Public IP FIx
 * Plugin URI:  https://chrisk.io
 * Description: For testing IP sensitive code, use the public facing IP in your localhost
 * Version:     1.0
 * Author:      Filament Studios
 * Author URI:  https://filament-studios.com
 * License:     GPL-2.0+
 */

/**
 *
 * The point of this plugin is to allow a local development environment to identify
 * the REMOTE_ADDR of the user as the public facing IP, which is able to be used in
 * GeoIP lookups and WHOIS checks for things like fraud services and other types of
 * eCommerce and rate limiting checks
 *
 */


if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

function kfg_use_external_ip() {

	$ip = get_transient( '_kfg_remote_ip' );

	if ( false === $ip ) {
		$response = wp_remote_get( 'http://bot.whatismyipaddress.com/' );

		if ( ! is_wp_error( $response ) ) {
			$body = wp_remote_retrieve_body( $response );
			$ip = $body;
			set_transient( '_kfg_remote_ip', $ip, HOUR_IN_SECONDS );
		}

	}

	if ( false !== filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) {
		$_SERVER['REMOTE_ADDR'] = $ip;
	}

}
add_action( 'plugins_loaded', 'kfg_use_external_ip', 1 );

Posted by Chris Klosowski

Chris Klosowski is the Director of Technology at Sandhills Development, LLC, creators of fine WordPress plugins, and ecommerce solutions.

32 Comments

  1. tadalafil research tadalafil side effects tadalafil troche cost

    Reply

  2. Hello there, You have done a great job. I’ll definitely digg it and personally recommend to
    my friends. I’m confident they will be benefited
    from this website.

    Reply

  3. After checking out a few of the blog posts on your blog,
    I really appreciate your way of blogging.
    I book marked it to my bookmark webpage list and will be checking back soon. Please check out my website as
    well and let me know what you think.

    Reply

  4. purchase viagra melbourne buy viagra 150 mg ViagraCND100Mg – get viagra in canada

    Reply

  5. buy viagra professional viagra connect usa – cheap viagra reviews

    Reply

  6. viagra online prescription indian viagra otfnpea – gneric viagra

    Reply

  7. zithromax tablets zithromax online – zithromax 1000 mg pills

    Reply

  8. prednisone pills cost buy prednisone – prednisone 50mg cost

    Reply

  9. where can i buy zithromax medicine generic zithromax – how to get zithromax over the counter

    Reply

  10. ivermectin 6mg ivermectin 12 mg tablets for sale – ivermectin generic cream

    Reply

  11. how much does ivermectin cost ivermectin for sale humans – ivermectin 8 mg

    Reply

  12. ivermectin 3 mg ivermectin for sale humans – stromectol cvs

    Reply

  13. buy stromectol canada stromectol 3 mg tablets price – ivermectin over the counter canada

    Reply

  14. aspirin and ed prescription meds without the prescriptions – erectile dysfunction medicines

    Reply

  15. erectile dysfunction drug causes of ed – medicine erectile dysfunction

    Reply

  16. soma therapy ed prescription drugs without prior prescription – over the counter ed remedies

    Reply

  17. buy medications online ed meds online without doctor prescription – over the counter ed medication

    Reply

  18. medicine erectile dysfunction prescription drugs online without doctor – errectile dysfunction

    Reply

  19. lexapro 15mg buy lexapro – where can you buy lexapro

    Reply

  20. lexapro price comparison lexapro generic – lexapro discount

    Reply

  21. hydroxychloroquine tablet ip 200 mg plaquenil arthritis – hydroxychloroquine 900mg

    Reply

  22. lexapro buy lexapro – how much is lexapro in australia

    Reply

  23. plaquenil eye hydroxychloroquinegnr – hydroxychloroquine oral

    Reply

  24. best pill for ed buy prescription drugs from canada – canadian drugstore online

    Reply

  25. to buy cialis generic cialis discounts – cialis for sale in toront ontario

    Reply

  26. Incredible story there. What happened after? Good luck!

    Reply

  27. online doctor prescription for viagra viagra without a doctor prescription usa – where can i buy viagra over the counter

    Reply

Leave a reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.