<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tech stuff &#187; gps</title>
	<atom:link href="http://codytaylor.org/tag/gps/feed" rel="self" type="application/rss+xml" />
	<link>http://codytaylor.org</link>
	<description>From Cody Taylor.</description>
	<lastBuildDate>Sun, 30 Oct 2011 04:15:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Match An IP Address To A Physical Location With PHP</title>
		<link>http://codytaylor.org/2009/06/match-an-ip-address-to-a-physical-location-with-php.html</link>
		<comments>http://codytaylor.org/2009/06/match-an-ip-address-to-a-physical-location-with-php.html#comments</comments>
		<pubDate>Thu, 11 Jun 2009 01:14:07 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[ip address location]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14116</guid>
		<description><![CDATA[Sometimes it's useful to locate where a certain IP address...]]></description>
			<content:encoded><![CDATA[<p>Sometimes it&#8217;s useful to locate where a certain IP address is located. Usually this isn&#8217;t really that accurate but at least it gives you a general idea for stats or marketing research. I&#8217;ve written a simple php function that uses curl to query a IP address location database for the location info. In the function I specify that I want a JSON data structure containing the location information. I chose JSON over the XML alternative just for ease of use. The object that we get returned needs to be referenced in a specific kind of way. I show how under the function.<br />
This function uses the <a href='http://ipinfodb.com/ip_location_api_json.php' title='IPInfoDB JSON php API'>IPInfoDB JSON php API</a>. There are quite a few alternatives out there so feel free to do your research. The IPInfoDB PHP API returns :</p>
<ul>
<li>Country Code (CA or US)</li>
<li>Country Name (Canada)</li>
<li>Region Code</li>
<li>Region Name (Province or Dtate)</li>
<li>City</li>
<li>Postalcode or Zip Code (which doesn&#8217;t always work)</li>
<li>Latitude</li>
<li>Longitude</li>
<li>gmt offset</li>
<li>Dst offset</li>
</ul>
<p><pre><code>
function get_location_info($ip_address)
{
&nbsp;&nbsp;$url = &#039;http://ipinfodb.com/ip_query.php?ip=&#039;;
&nbsp;&nbsp;$url .= $ip_address;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$url .= &#039;&amp;output=json&#039;;
&nbsp;&nbsp;$ch = curl_init();
&nbsp;&nbsp;
&nbsp;&nbsp;curl_setopt($ch, CURLOPT_URL, $url);
&nbsp;&nbsp;curl_setopt($ch, CURLOPT_HEADER, 0);
&nbsp;&nbsp;curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;$json_packet = curl_exec($ch);
&nbsp;&nbsp;$location_array = json_decode($json_packet);
&nbsp;&nbsp;curl_close($ch);
&nbsp;&nbsp;return($location_array);

}//get_location_info

$loc_arr = get_location_info(&quot;69.157.107.64&quot;);
echo &quot;\n&quot;;
echo $loc_arr-&gt;{&#039;City&#039;};
echo &quot;\n&quot;;
echo $loc_arr-&gt;{&#039;RegionName&#039;};
echo &quot;\n&quot;;
echo $loc_arr-&gt;{&#039;CountryCode&#039;};
</code></pre></p>
<p>Hopefully theres no confusion there.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F06%2Fmatch-an-ip-address-to-a-physical-location-with-php.html&amp;linkname=Match%20An%20IP%20Address%20To%20A%20Physical%20Location%20With%20PHP"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/06/match-an-ip-address-to-a-physical-location-with-php.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

