1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

need go redirect script

Discussion in 'PHP & Perl' started by pcmoseley, Jul 6, 2013.

  1. pcmoseley

    pcmoseley Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 13, 2007
    Messages:
    367
    Likes Received:
    93
    Location:
    Denver CO
    I really need a simple php or other script to send visitors to a url based on their country code. I found this http://pastebin.com/m923hKz6 but it's not working for me (i'm a noob at coding). I put in my US url and saved it as index.html and index.php but it didn't work
     
  2. Izzma

    Izzma Regular Member

    Joined:
    Jan 29, 2012
    Messages:
    293
    Likes Received:
    197
    Location:
    Canada
    Nvm, saw include
     
  3. splawnnitro

    splawnnitro Jr. VIP Jr. VIP Premium Member

    Joined:
    Dec 18, 2011
    Messages:
    160
    Likes Received:
    100
  4. pcmoseley

    pcmoseley Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 13, 2007
    Messages:
    367
    Likes Received:
    93
    Location:
    Denver CO

    What is this Speedy Share crap? Like I said, I'm looking for straight code here. Is this your affiliate link and are you trying to get banned?
     
  5. supapera

    supapera Regular Member

    Joined:
    Sep 12, 2010
    Messages:
    212
    Likes Received:
    132
    Occupation:
    rushing long
    Location:
    de_dust2
    here you go, works for me

    PHP:
    <?php

    include("geo/geoip.inc");
    $ip=$_SERVER['REMOTE_ADDR'];
    $gi geoip_open("geo/GeoIP.dat",GEOIP_STANDARD);

    $country_code geoip_country_code_by_addr($gi"$ip");

    // Country name is not used so commented
    // Get Country Name based on source IP
    //$country = geoip_country_name_by_addr($gi, "$ip");

    geoip_close($gi);

    switch(
    $country_code)

        {
            case 
    "US"header("Location: http://offerforusa.com"); break;
            case 
    "CA"header("Location: http://offerforcanada.com"); break;
            case 
    "UK"header("Location: http://offerforuk.com"); break;
            case 
    "AU"header("Location: http://offerforaustralia.com"); break;
            case 
    "NZ"header("Location: http://offerfornewzealand.com"); break;
            default: 
    header("Location: http://offerforothers.com");
    }
    ?>
    as you can see, you will need geoip.inc and geoip.dat
    you know where to find that

    Code:
    http://www63.zippyshare.com/v/83299748/file.html
    Code:
    https://www.virustotal.com/en/file/e6179af4ebe88a223401dfdcc9e5cf24e0d92e42deab513179e48d1eb7489da2/analysis/1373150418/
     
    • Thanks Thanks x 1
    Last edited: Jul 6, 2013
  6. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    Try my geo-redirect capabilities at http://www.monojump.com
     
    • Thanks Thanks x 1
  7. pcmoseley

    pcmoseley Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 13, 2007
    Messages:
    367
    Likes Received:
    93
    Location:
    Denver CO
    I tested your script but it's not working for me. I added geoip.inc and geoip.dat to the main folder and also left it in the geo folder but it's still giving me the same error http://paulmoseley.com/tracking
     
  8. conzy

    conzy Newbie

    Joined:
    Jun 21, 2013
    Messages:
    2
    Likes Received:
    0
    Put geoip.inc and geoip.dat files on subfolder named 'geo' and then try it out.
     
  9. supapera

    supapera Regular Member

    Joined:
    Sep 12, 2010
    Messages:
    212
    Likes Received:
    132
    Occupation:
    rushing long
    Location:
    de_dust2
    yep, as conzy said geoip.inc and geoip.dat goes in /geo folder

    OR

    if you want to have geoip.inc and geoip.dat in same folder as index.php, then remove "geo/" on 3rd and 5th line
    then your new index.php will be:
    PHP:
     <?php

    include("geoip.inc");
    $ip=$_SERVER['REMOTE_ADDR'];
    $gi geoip_open("GeoIP.dat",GEOIP_STANDARD);

    $country_code geoip_country_code_by_addr($gi"$ip");

    // Country name is not used so commented
    // Get Country Name based on source IP
    //$country = geoip_country_name_by_addr($gi, "$ip");

    geoip_close($gi);

    switch(
    $country_code)

        {
            case 
    "US"header("Location: http://offerforusa.com"); break;
            case 
    "CA"header("Location: http://offerforcanada.com"); break;
            case 
    "UK"header("Location: http://offerforuk.com"); break;
            case 
    "AU"header("Location: http://offerforaustralia.com"); break;
            case 
    "NZ"header("Location: http://offerfornewzealand.com"); break;
            default: 
    header("Location: http://offerforothers.com");
    }
    ?>
     
  10. pcmoseley

    pcmoseley Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 13, 2007
    Messages:
    367
    Likes Received:
    93
    Location:
    Denver CO
    I tried it this way first thing.
     
  11. pcmoseley

    pcmoseley Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 13, 2007
    Messages:
    367
    Likes Received:
    93
    Location:
    Denver CO
    I tried it with the folder but same error..
     
  12. pcmoseley

    pcmoseley Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 13, 2007
    Messages:
    367
    Likes Received:
    93
    Location:
    Denver CO
    So far monojump has been promising and seems to work well. Thanks for this. How much for self hosted license?
     
  13. inviz

    inviz Newbie

    Joined:
    Jun 15, 2010
    Messages:
    45
    Likes Received:
    5
    Hello, I havent tested this.. Just something i came up with using the freegeoip API.. Please reply if it's not working..

    Code:
    <?php
    function freegeoip_locate($ip) {
    	$url = "http://freegeoip.net/json/" . $ip;
    	$geo = json_decode(file_get_contents($url), true);
    	return $geo;
    }
    
    
    $geo = freegeoip_locate($_SERVER['REMOTE_ADDR']);
    $country_code = $geo['country_code'];
    
    
    switch($country_code) {
    	case "US" :
    		header("Location: http://offerforusa.com");
    		break;
    	case "CA" :
    		header("Location: http://offerforcanada.com");
    		break;
    	case "UK" :
    		header("Location: http://offerforuk.com");
    		break;
    	case "AU" :
    		header("Location: http://offerforaustralia.com");
    		break;
    	case "NZ" :
    		header("Location: http://offerfornewzealand.com");
    		break;
    	default :
    		header("Location: http://offerforothers.com");
    }
    ?>