How to redirect domain according to country IP address

In General
1303

How to redirect domain according to country IP address

The PHP web service allows you to directly program your back-end PHP scripts to deliver dynamic geo-localized pages using the PHP array provided by GeoPlugin.

For access this service, you need to add the following url to a remote include call

http://www.geoplugin.net/php.gp?ip=xx.xx.xx.xx (in the place of 'xx.xx.xx.xx.' you can use your IP Address like '11.22.33.44')

Add the below code in your php file where you want and then change the 'IN' to your country code like 'UK', 'USA', etc., and in the place of domain name 'https://pcmshaper.com' to your domain.

<?php 
$meta = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR']));
if($meta['geoplugin_countryCode']=='IN')
{
	header('Location: https://pcmshaper.com');
}
?>

If you would like to print or debug geo location API then use the below code.

<?php
$meta = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR']));
echo "<pre>";
print_r($meta);
echo "<//pre>"; ?>

You can check more details about the geo location API at http://www.geoplugin.com/webservices/php

We hope it will helpful to all visitors!!

Rating
  • (1 Ratings)