hi,
i want to redirect indian user's to a page and all other country's user to another page?
how to do it?
i want to redirect indian user's to a page and all other country's user to another page?
how to do it?
<?php
$ip=$_SERVER['REMOTE_ADDR'];
geoCheckIP($ip);
//Get an array with geoip-infodata
function geoCheckIP($ip)
{
//check, if the provided ip is valid
if(!filter_var($ip, FILTER_VALIDATE_IP))
{
throw new InvalidArgumentException("IP is not valid");
}
//contact ip-server
$response=@file_get_contents('http://www.netip.de/search?query='.$ip);
if (empty($response))
{
throw new InvalidArgumentException("Error contacting Geo-IP-Server");
}
//Array containing all regex-patterns necessary to extract ip-geoinfo from page
$patterns=array();
$patterns["domain"] = '#Domain: (.*?) #i';
$patterns["country"] = '#Country: (.*?) #i';
$patterns["state"] = '#State/Region: (.*?)<br#i';
$patterns["town"] = '#City: (.*?)<br#i';
//Array where results will be stored
$ipInfo=array();
//check response from ipserver for above patterns
foreach ($patterns as $key => $pattern)
{
//store the result in array
$ipInfo[$key] = preg_match($pattern,$response,$value) && !empty($value[1]) ? $value[1] : 'not found';
}
return $ipInfo;
}
$my_array=geoCheckIP($ip);
foreach ($my_array as $key => $value){
if($key=='country'){
#switch on the country:
switch ($value) {
case 'IN - India':
echo "('header : ../index2.php')";
break;
default :
echo "('header : ../index3.php')":
break;
}
}
}
?>
switch ($value) {
case 'IN - India': header('Location:../index2.php');
break;
default : header('Location:../index3.php');
break;
}
<?php
function gum_real_ip()
{
$keyname_ip_arr = array('HTTP_X_FORWARDED_FOR', 'HTTP_REMOTE_ADDR_REAL', 'HTTP_CLIENT_IP', 'HTTP_X_REAL_IP', 'REMOTE_ADDR');
foreach ($keyname_ip_arr as $keyname_ip) {
if (!empty($_SERVER[$keyname_ip])) {
$ip = $_SERVER[$keyname_ip];
break;
}
}
if (strstr($ip, ',')) {
$ips = explode(',', $ip);
if(substr($ips[0], 1, 3)=='10.'&&strlen($ips[1])>5)
$ip = trim($ips[1]);
else $ip = trim($ips[0]);
}
if(!preg_match("^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}^", $ip)) $ip = $_SERVER["REMOTE_ADDR"];
return $ip;
list($ip1,$ip2,$ip3,$ip4) = explode('.',$ip);
return $ip1.'.'.$ip2.'.'.$ip3.'.0'; //REAL IP
}
$ip = gum_real_ip();
//& continue with the below code
<?php
function gum_real_ip()
{
$keyname_ip_arr = array('HTTP_X_FORWARDED_FOR', 'HTTP_REMOTE_ADDR_REAL', 'HTTP_CLIENT_IP', 'HTTP_X_REAL_IP', 'REMOTE_ADDR');
foreach ($keyname_ip_arr as $keyname_ip) {
if (!empty($_SERVER[$keyname_ip])) {
$ip = $_SERVER[$keyname_ip];
break;
}
}
if (strstr($ip, ',')) {
$ips = explode(',', $ip);
if(substr($ips[0], 1, 3)=='10.'&&strlen($ips[1])>5)
$ip = trim($ips[1]);
else $ip = trim($ips[0]);
}
if(!preg_match("^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}^", $ip)) $ip = $_SERVER["REMOTE_ADDR"];
return $ip;
list($ip1,$ip2,$ip3,$ip4) = explode('.',$ip);
return $ip1.'.'.$ip2.'.'.$ip3.'.0'; //REAL IP
}
function geoCheckIP($ip)
{
//check, if the provided ip is valid
if(!filter_var($ip, FILTER_VALIDATE_IP))
{
throw new InvalidArgumentException("IP is not valid");
}
//contact ip-server
$response=@file_get_contents('http://www.netip.de/search?query='.$ip);
if (empty($response))
{
throw new InvalidArgumentException("Error contacting Geo-IP-Server");
}
//Array containing all regex-patterns necessary to extract ip-geoinfo from page
$patterns=array();
$patterns["domain"] = '#Domain: (.*?) #i';
$patterns["country"] = '#Country: (.*?) #i';
$patterns["state"] = '#State/Region: (.*?)<br#i';
$patterns["town"] = '#City: (.*?)<br#i';
//Array where results will be stored
$ipInfo=array();
//check response from ipserver for above patterns
foreach ($patterns as $key => $pattern)
{
//store the result in array
$ipInfo[$key] = preg_match($pattern,$response,$value) && !empty($value[1]) ? $value[1] : 'not found';
}
return $ipInfo;
}
$ip = gum_real_ip();
$my_array=geoCheckIP($ip);
foreach ($my_array as $key => $value){
if($key=='country'){
#switch on the country:
switch ($value) {
case 'IN - India':
header("location:indian_visitors.php");
break;
default :
header("location:other_visitors.php");
break;
}
}
}
?>
Comment