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
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 Web Developer. Contact me with nice budgets for crazy projects.
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 Web Developer. Contact me with nice budgets for crazy projects.
Reply
2016-09-16, 04:58 AM,
#8
Yea fixed. Was trying on a host without PHP enabled :D
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Where should I put <script> tags in HTML? Pirata 5 176 2017-12-03, 11:38 AM
Last Post: Pirata
  Affiliate Network With More Geo's for Weight Loss Niche Ghettoweed 5 221 2017-11-17, 08:18 PM
Last Post: Ana_AdCombo
  [JAVA SCRIPT] Need someone to make me an executable!!! CagelessBrain 0 110 2017-10-17, 04:09 AM
Last Post: CagelessBrain
  How To Detect get Script In Landing Page 5light 3 181 2017-10-05, 04:04 AM
Last Post: LB'Decoy
  [HELP] Codes/Script from a BH site to mine cracklings1017 3 187 2017-08-20, 10:58 AM
Last Post: FarrisFahad





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

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