SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    include() statement - injecting value into a variable

    Hi,
    I'm trying to form a simple geo-targeting call, using Using the Database - IP Address Lookup - Community Geotarget IP Addresses Project , in which I insert my site visitor's country into a URL, and act accordingly.

    Basically, if you click on http://api.hostip.info/country.php it returns your 2-letter country code, so I would like to do something like:
    Code:
    $country=include(http://api.hostip.info/country.php);
    But of course, this syntax actually returns $country = 1 (success) or 0 (failure).
    How do I get it to return $country = US (or UK, or SE etc.)?

    Thanks!
    Andy

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    Use file_get_contents instead of include.

    If that doesn't work (it should, or your include would have failed), you'll have to do something like cURL the page to get the data into a variable.

    Ps - this will only return the SERVERs country of origin. If you want the clients, you'll need to feed that page some data somehow.

  3. #3
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That was quick! Thanks!
    No problem injecting the client IP once I get it. something like
    PHP Code:
    file_get_contents(http://api.hostip.info/country.php?ip=VISITORS_IP) 
    Will try that 1st thing tomorrow and post here whether it worked.
    Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •