Copyright © 2005-2008 Andrea Tincani

AndreaPHP | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (SQL)Next Topic (replace _blank with _top using eregi_replace) New Topic New Poll Post Reply
AndreaPHP Forum : PHP General : Geo target function
Poster Message
admin
Level: Administrator


Registered: 04-04-2002
Posts: 35

icon Geo target function

I've found this interesting function used to check the country for your site's visitors


<?php
function CheckCountry()
{
  
// make a valid request to the hostip.info API
  
if ($_SERVER['HTTP_X_FORWARD_FOR']) {
    
$ip $_SERVER['HTTP_X_FORWARD_FOR'];
  } else {
    
$ip $_SERVER['REMOTE_ADDR'];
  }
  
$url "http://api.hostip.info/country.php?ip=".$ip;
  
// fetch with curl
  
$ch curl_init();
  
curl_setopt($chCURLOPT_URL$url);
  
curl_setopt($chCURLOPT_HEADER0);
  
curl_setopt($chCURLOPT_RETURNTRANSFER1);
  
$country curl_exec($ch);
  
curl_close ($ch);
  return 
$country;
}
?>




I've used it to geo-target one of my Ad campaign to canadian users only...

hope you find it useful

____________________________
AndreaVB

07-03-2006 at 08:28 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaPHP Forum : PHP General : Geo target function
Previous Topic (SQL)Next Topic (replace _blank with _top using eregi_replace) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: AndreaVB

Copyright © 2005-2008 Andrea Tincani

Powered by: tForum tForum Edition b0.92p1
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team.