Country Detect Script for CPA website.

Discussion in 'Programming' started by upshiftmedia, Aug 21, 2008.

  1. #1
    Hey Forum,

    I am building a site that I only would like USA members to join. Is there a script that will detect the visitors location and redirect them if they are not from USA? I have seen one used by cpastorm and would like to use something similar.

    Thanks,

    Mike
     
    upshiftmedia, Aug 21, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    I can create it for you for a small $$, PM me for more info!
     
    EricBruggema, Aug 21, 2008 IP
  3. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #3
    Use Maxmind's GeoIP.
     
    mwasif, Aug 22, 2008 IP
  4. abluegrape

    abluegrape Peon

    Messages:
    1,029
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Easy enough to do in Perl or PHP - which language you using on your site?
     
    abluegrape, Aug 22, 2008 IP
  5. upshiftmedia

    upshiftmedia Peon

    Messages:
    469
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I will be making the site PHP. I will also need this script to detect proxies and not allow proxies on the site. I don't think GeoIP does this or am I wrong?
     
    upshiftmedia, Aug 23, 2008 IP
  6. abluegrape

    abluegrape Peon

    Messages:
    1,029
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    How soon do you want something sorted, I am a bit jammed coding stuff for a few other people, but could probably do something for you if you want.

    I wouldn't charge but donations are always appreciated - feel free to drop me a PM if you want to give me the details :)

    Cheers
    Ry
     
    abluegrape, Aug 23, 2008 IP
  7. abluegrape

    abluegrape Peon

    Messages:
    1,029
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    In fact, here is something thats rough and ready.
    It should check if proxy is used and give you the true IP address and the country shortcode (US / UK / DE etc)

    Hope it helps - if you have probs, PM away.

    
    <?php
    	if (!empty($_SERVER['HTTP_CLIENT_IP']))
    	{
    		$ip=$_SERVER['HTTP_CLIENT_IP'];
                   // This visitor is using a proxy, this should be the true IP - so do what you have to to deny proxy user 
    	}
    	elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    	{
    		$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
                    // This visitor is using a proxy, this should be the true IP - so do what you have to to deny proxy user
    	}
    	else
    	{
    		$ip=$_SERVER['REMOTE_ADDR'];
                   // This is the proper IP address, not a proxied one so
    	}
        
    	$country = file_get_contents('http://api.hostip.info/country.php?ip='.$ip);
    	print "IP = $ip<br>Country = $country<br>";
    	
    ?>
    
    Code (markup):
     
    abluegrape, Aug 23, 2008 IP
    happpy and depi like this.
  8. upshiftmedia

    upshiftmedia Peon

    Messages:
    469
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Pm you the details. Thanks.
     
    upshiftmedia, Aug 26, 2008 IP
  9. depi

    depi Active Member

    Messages:
    845
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    68
    #9
    abluegrape thanks for the script (and especially for that API), that's what I was just looking for :)
     
    depi, Oct 5, 2008 IP
  10. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #10
    Barti1987, Oct 6, 2008 IP
  11. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #11
    quoted for quality!
     
    happpy, Oct 6, 2008 IP