Redirect domain according to country IP address using php


<?php
require_once ‘IP2Location.php’;

$db = new IP2LocationDatabase(‘databases/IP2LOCATION-LITE-DB1.BIN’, IP2LocationDatabase::FILE_IO);

$records = $db->lookup($_SERVER[‘REMOTE_ADDR’], IP2LocationDatabase::ALL);

if($records[‘countryCode’] == ‘NP’) {
    header(‘Location: http://sugatshrestha.com.np’);
    exit;
}

?>

Requirement: Install IP2Location PHP Module first.

PHP Web development