hi, i want to redirect indian user's to a page and all other country's user to another page? how to do it?
External image (may be gone) http://WapTops.com- Get Real High Traffic http://WapFun.info-Fun 4 Wap
Started on the old forum in November 2011 · view the original in the archive · old links redirect here
hi, i want to redirect indian user's to a page and all other country's user to another page? how to do it?
External image (may be gone) http://WapTops.com- Get Real High Traffic http://WapFun.info-Fun 4 Wap
<?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;
}
}
}
?>
all indian users redirect to index2.php page and othe country user index3.php page. Call this in in your top of index page using include function.
its just printing ('header : ../index2.php')";
External image (may be gone) http://WapTops.com- Get Real High Traffic http://WapFun.info-Fun 4 Wap
Switch should be like this
switch ($value) {
case 'IN - India': header('Location:../index2.php');
break;
default : header('Location:../index3.php');
break;
}
s3nzo wrote: Switch should be like this
switch ($value) { case 'IN - India': header('Location:../index2.php'); break; default : header('Location:../index3.php'); break; }
working thanks
External image (may be gone) http://WapTops.com- Get Real High Traffic http://WapFun.info-Fun 4 Wap
if ip is wrong, then how to redirect it to other page?????
External image (may be gone) http://WapTops.com- Get Real High Traffic http://WapFun.info-Fun 4 Wap
slowy wrote: if ip is wrong, then how to redirect it to other page?????
You mean if the user is behind a proxy?
I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID
softwarefreak wrote: You mean if the user is behind a proxy?
ya if user is behind anonymous proxy then country is showing empty so i want to reirect these users to another page
External image (may be gone) http://WapTops.com- Get Real High Traffic http://WapFun.info-Fun 4 Wap
<?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
I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID
<?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;
}
}
}
?>
This shud work now..
I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID
here other_visitors =anonymous proxy users?
External image (may be gone) http://WapTops.com- Get Real High Traffic http://WapFun.info-Fun 4 Wap
slowy wrote: here other_visitors =anonymous proxy users?
NO 😀,the real ip will be detected(even if they are using proxy) & then they will be redirected like b4,other_visitors.php is the location you want to send ppl from countries other than India 🙂
I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID