Help me to fix this Geo redirection script
2016-09-14, 10:59 PM,
#1
Hi guys!
So, I have been trying to set this script to redirect users to other page based on geolocations after an interval of time and I'm facing some errors.

Can someone kindly help me fix this error?

PHP Code:
<!DOCTYPE html>
<
html lang="en"><head>



<
meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <
meta charset="utf-8">
  <
meta http-equiv="x-ua-compatible" content="ie=edge">
  <
meta name="viewport" content="width=device-width, initial-scale=1">
  <
meta name="robots" content="noindex, nofollow">
  
</
head>
<
body>
<?
php


Function get_data($url) {
    
$ch curl_init();
    
$timeout 5;
    
curl_setopt($chCURLOPT_URL$url);
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt($chCURLOPT_CONNECTTIMEOUT$timeout);
    
$data curl_exec($ch);
    
curl_close($ch);
    return 
$data;
}

$ipaddress $_SERVER["REMOTE_ADDR"];
$call get_data('http://freegeoip.net/csv/' $ipaddress);
$country preg_split("/[\s,]+/"$call);





if (
$country[1] == "US") {
  
header("refresh:5;url=http://example.com/us.php");

elseif (
$country[1] == "CA") {
  
header("refresh:5;url=http://example.com/ca.php");


else {
  
header("refresh:5;url=http://example.com/other.php");
}

exit();
?>

    
<center>
<h3>You are being Redirected</h3>



</center>
</body>
</html> 

Thank you.
Reply
Share This Thread :
2016-09-14, 11:02 PM,
#2
There is a good one here http://www.cpaelites.com/tools/
tryed it and it works grate
Reply
2016-09-14, 11:09 PM,
#3
(2016-09-14, 11:02 PM)pepeneo Wrote: There is a good one here /tools/
tryed it and it works grate

Thanks for your reply mate, but I don't have vip status. :)
Reply
2016-09-15, 04:06 AM,
#4
Here u go. Make sure php script is always above all content. There's also limits using 3d parties to check IP's country. It's something about 100 visitors/minutes.

Code:
<?php


$call = unserialize(file_get_contents('http://ip-api.com/php/'.$_SERVER['REMOTE_ADDR']));
$country = $call["countryCode"];




if ($country == "US") {
  header("Location: url=http://example.com/us.php");
}
elseif ($country == "CA") {
  header("Location: http://example.com/ca.php");
}
elseif ($country == "MX") {
  header("Location: http://example.com/mx.php");
}
elseif ($country == "ID") {
  header("Location: http://example.com/id.php");
}
elseif ($country == "PH") {
  header("Location: http://example.com/ph.php");
}

else {
  header("Location: http://example.com/other.php");
}


exit();
?>
<!DOCTYPE html>
<html lang="en"><head>



<meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="robots" content="noindex, nofollow">
  
</head>
<body>


    
<center>
<h3>You are being Redirected</h3>



</center>
</body>
</html>
Latest Thanks - View all

r00tb0t(2016-09-15 11:50 AM) 

I'm a Web Developer. Contact me for bigger projects only.
Reply
2016-09-15, 11:53 AM, (This post was last modified: 2016-09-15, 01:42 PM by r00tb0t.)
#5
(2016-09-15, 04:06 AM)SuperSimple Wrote: Here u go. Make sure php script is always above all content. There's also limits using 3d parties to check IP's country. It's something about 100 visitors/minutes.

Code:
<?php


$call = unserialize(file_get_contents('/php/'.$_SERVER['REMOTE_ADDR']));
$country = $call["countryCode"];




if ($country == "US") {
  header("Location: url=/us.php");
}
elseif ($country == "CA") {
  header("Location: /ca.php");
}
elseif ($country == "MX") {
  header("Location: /mx.php");
}
elseif ($country == "ID") {
  header("Location: /id.php");
}
elseif ($country == "PH") {
  header("Location: /ph.php");
}

else {
  header("Location: /other.php");
}


exit();
?>
<!DOCTYPE html>
<html lang="en"><head>



<meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="robots" content="noindex, nofollow">
  
</head>
<body>


    
<center>
<h3>You are being Redirected</h3>



</center>
</body>
</html>

Thanks for your code supersimple. What I need is the user needs to wait 5 seconds before being redirected to another site.
I tried to use
Code:
header("refresh:5;url=http://example.com/ca.php");
for that reason. Will this work?
EDIT:
Ok, I got this right
Code:
header("refresh:5;url=http://google.com");
  echo 'You are being redirected';
Reply
2016-09-15, 12:29 PM,
#6
Thanks for the code. Is there a guide on how to set this up? I setup us traffic to visit google.com and rest to cpaelites.com but when i tested the script i was redirected to google and the script file was auto downloaded. I am not from the US and the script should not download. Can you point me in the right direction please?





(2016-09-15, 04:06 AM)SuperSimple Wrote: Here u go. Make sure php script is always above all content. There's also limits using 3d parties to check IP's country. It's something about 100 visitors/minutes.

Code:
<?php


$call = unserialize(file_get_contents('/php/'.$_SERVER['REMOTE_ADDR']));
$country = $call["countryCode"];




if ($country == "US") {
  header("Location: url=/us.php");
}
elseif ($country == "CA") {
  header("Location: /ca.php");
}
elseif ($country == "MX") {
  header("Location: /mx.php");
}
elseif ($country == "ID") {
  header("Location: /id.php");
}
elseif ($country == "PH") {
  header("Location: /ph.php");
}

else {
  header("Location: /other.php");
}


exit();
?>
<!DOCTYPE html>
<html lang="en"><head>



<meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="robots" content="noindex, nofollow">
  
</head>
<body>


    
<center>
<h3>You are being Redirected</h3>



</center>
</body>
</html>
Reply
2016-09-15, 05:11 PM,
#7
(2016-09-15, 11:53 AM)r00tb0t Wrote: Ok, I got this right
Code:
header("refresh:5;url=");
  echo 'You are being redirected';

Yep, you got this ;)

(2016-09-15, 12:29 PM)userabuser Wrote: Thanks for the code. Is there a guide on how to set this up? I setup us traffic to visit google.com and rest to cpaelites.com but when i tested the script i was redirected to google and the script file was auto downloaded. I am not from the US and the script should not download. Can you point me in the right direction please?

Just copy paste this script php file and change your links for every country.

I'm a Web Developer. Contact me for bigger projects only.
Reply
2016-09-16, 04:58 AM,
#8
Yea fixed. Was trying on a host without PHP enabled :D
Reply


Related Threads
Thread Author Replies Views Last Post
  REQ Movie affiliate CPA Php script mineshparikh 2 97 2018-02-16, 01:11 AM
Last Post: Kjartansson
  [ASK] Movie Streaming Website Script sonpink 19 4,353 2018-02-15, 05:21 PM
Last Post: mineshparikh
  Script Facebook daavin 4 219 2018-02-08, 11:29 PM
Last Post: faithalo
  How to put HTML landing page script in blogger walterzingo 4 202 2018-02-03, 06:55 PM
Last Post: umberblue
  "does this tool work" script? how to use this on my site?? dipak777 9 330 2018-01-26, 01:08 AM
Last Post: dipak777





About Us | Contact Us | CPA Elites | Advertise | Stats | Staff Team

© 2013-2018 CPA Elites Ltd
Enhanced by MyBB and WallBB
Return to top