phpadsnew & Geotargeting

Discussion in 'PHP' started by mad4, Nov 28, 2006.

  1. #1
    Can anyone give me some pointers on the easy way to access the country data of my users in php?

    I am running the phpadsnew & maxmind DB at the minute but I would like to be able to access the country data directly from a php script rather than via phpadsnew. The manual says I can set a cookie but I can't figure out what the cookie is doing.:confused:

    Edit: using this, any better ideas?

    	if (isset($_COOKIE["geo"])) {
        $country = $_COOKIE['geo'];
        } 
        else 
        {
        include("geoip.inc");
        $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
        $country = geoip_country_code_by_addr($gi, $REMOTE_ADDR);
        geoip_close($gi);
        setcookie("geo", $country, time()+432000, "/", ".mad4mobilephones.com", 0); 
        }
    Code (markup):
     
    mad4, Nov 28, 2006 IP
  2. zenglider

    zenglider Peon

    Messages:
    18
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Maxmind should have an API that can do that for you.
     
    zenglider, Nov 28, 2006 IP
  3. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I've got it working using the code above. Just seems that I am querying twice for each user. Once for phpadsnew and once for my script. Would be better if I could access whatever cookie phpadsnew is setting from my php script.
     
    mad4, Nov 28, 2006 IP