include() statement - injecting value into a variable - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-01-2011, 05:28 AM   #1 (permalink)
Junior Member
 
Join Date: Sep 2011
Posts: 1
Default include() statement - injecting value into a variable

Hi,
I'm trying to form a simple geo-targeting call, using hxxp://w_w_w.hostip.info/use.html, in which I insert my site visitor's country into a URL, and act accordingly.

Basically, if you click on hxxp://api.hostip.info/country.php it returns your 2-letter country code, so I would like to do something like:
Code:
$country=include(hxxp://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

PS - sorry about the hxxp instead of http
I'm not allowed to insert URLs here, but since I just want an aswer, with no spamming intended, I replaced http with hxxp and www with w_w_w

Last edited by shakennotstirred; 09-01-2011 at 05:50 AM.
shakennotstirred is offline   Reply With Quote
Sponsored Links
Old 09-02-2011, 04:45 PM   #2 (permalink)
Junior Member
 
Winleet's Avatar
 
Join Date: Aug 2011
Posts: 13
Default Re: include() statement - injecting value into a variable

Using include like that simply returns a boolean value of whether the file exists or not.
If you want to use the script, add
include "hxxp://api.hostip.info/country.php";
to the top of your file, then look at country.php and any variables there can be used by your own file.
Winleet is offline   Reply With Quote
Old 09-05-2011, 10:44 PM   #3 (permalink)
Junior Member
 
Join Date: Sep 2011
Posts: 23
Default Re: include() statement - injecting value into a variable

shakennotstirred, what you want to use is curl, not php include. curl is much more efficient and including remote content is not enabled on all php installations, so it can be unreliable.

You want to do the following:
Quote:
function get_url($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
hoodle is offline   Reply With Quote
Old 09-16-2011, 03:36 PM   #4 (permalink)
Junior Member
 
Join Date: Sep 2011
Location: Long Islanf, NY, USA
Posts: 33
Default Re: include() statement - injecting value into a variable

If you send the user's IP address properly
Code:
http://api.hostip.info/get_html.php?ip=12.215.42.19
It returns the following text:
Code:
Country: UNITED STATES (US)
City: Aurora, TX
IP: 12.215.42.19
It's simple enough to parse out the country or abbreviation from that. Or you can use the XML version
Code:
http://api.hostip.info/?ip=12.215.42.19
to get an XML return which includes <gml:name>(the city), <countryName> and <countryAbbrev> data items.
Rukbat is offline   Reply With Quote
Old 05-14-2012, 06:00 AM   #5 (permalink)
Regular User
 
Join Date: May 2012
Location: usa
Posts: 18
Default Re: include() statement - injecting value into a variable

Quote:
$counttry = file_get_contents('hxxp://api.hostip.info/country.php');
if country.php file active . $country will return value
y8games2012 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 05:00 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting