Detect country and show content script

david120

Newbie
Joined
Jan 2, 2011
Messages
33
Reaction score
8
I created this script for a couple of my blogs which use a content locker, I wanted to switch my content locker to "Content lock pro" to try and cut out the middle man and make more money.

Lets just say I'm not exactly using the locker legitimatley and I'm going against these networks TOS. So I created a simple script to allows you to detect the users country and show content only to that country. So I would only show content lock pro to users orginating from the US and all other countries would get a default leadbolt content locker.

Change <API KEY> to the Ipinfodb's api key. You can sign up for a free api key at Ipinfodb.com

You can also change "UNITED STATES" to other countries such as "UNITED KINGDOM."

PHP:
<?php
$location = $_SERVER['REMOTE_ADDR'];
$ipp = simplexml_load_file("http://api.ipinfodb.com/v3/ip-country/?key=<API KEY>&ip=$location&format=xml");
$country = $ipp->countryName;
    
if ($country == "UNITED STATES") { ?>

<!-- ONLY DISPLAY CONTENT TO US USERS -->

<?php } else { ?>
    
<!--Every other country will see this content -->

<?php } ?>
 
This is awesome, this will be so useful.
The registration to get the api key was quick and simple.
Thanks
 
This will be nice if someone make this as wp plugin.
 
Back
Top