<?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>Money-Code &#187; geoip</title>
	<atom:link href="http://www.money-code.com/tag/geoip/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.money-code.com</link>
	<description>Coding For Online Success</description>
	<lastBuildDate>Tue, 15 Nov 2011 18:25:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>GeoIP Scripts PHP and JavaScript</title>
		<link>http://www.money-code.com/2009/06/geoip-scripts-php-and-javascript/</link>
		<comments>http://www.money-code.com/2009/06/geoip-scripts-php-and-javascript/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 00:02:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Affiliate Marketing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[geoip]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.money-code.com/?p=270</guid>
		<description><![CDATA[Last week I was reading Danger Brown&#8217;s &#8220;Easy geo/ip script to be sneaky with&#8220;, and oddly enough just days before that I was working on a server side solution to do the same thing. His example is using maxmind&#8217;s geoip.js script to determine where your referring IP address is coming from. Here is the script [...]


Related posts:<ol><li><a href='http://www.money-code.com/2009/07/monitor-your-sites-watch-your-logs/' rel='bookmark' title='Monitor your sites &#8211; Watch your logs'>Monitor your sites &#8211; Watch your logs</a></li>
<li><a href='http://www.money-code.com/2007/09/capture-search-data-on-your-site/' rel='bookmark' title='Capture search data on your site'>Capture search data on your site</a></li>
<li><a href='http://www.money-code.com/2008/01/problems-fetching-cj-product-feeds-with-phps-ftp-functionality/' rel='bookmark' title='Problems fetching CJ Product Feeds with PHP&#8217;s FTP functionality'>Problems fetching CJ Product Feeds with PHP&#8217;s FTP functionality</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.money-code.com%2F2009%2F06%2Fgeoip-scripts-php-and-javascript%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.money-code.com%2F2009%2F06%2Fgeoip-scripts-php-and-javascript%2F&amp;source=hanjicode&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Last week I was reading Danger Brown&#8217;s &#8220;<a href="http://dangerbrown.com/easy-geoip-script-to-be-sneaky-with/" target="_blank">Easy geo/ip script to be sneaky with</a>&#8220;, and oddly enough just days before that I was working on a server side solution to do the same thing. His example is using maxmind&#8217;s geoip.js script to determine where your referring IP address is coming from. Here is the script to do this client side using javascript.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;script language</span>=<span class="st0">&quot;JavaScript&quot;</span> src=<span class="st0">&quot;http://j.maxmind.com/app/geoip.js&quot;</span>&gt;&lt;/script&gt;<br />
<span class="kw2">&lt;script language</span>=<span class="st0">&quot;JavaScript&quot;</span>&gt;document.write<span class="br0">&#40;</span>geoip_city<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;&lt;/script&gt;<br />
<span class="kw2">&lt;script language</span>=<span class="st0">&quot;JavaScript&quot;</span>&gt;document.write<span class="br0">&#40;</span>geoip_region<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;&lt;/script&gt;</div>
<p><a href="http://www.maxmind.com/app/ip-locate" target="_blank">MaxMind</a> creates IP geolocation services and offers this server for free or at a cost, depending on your needs. I wanted to be able to add some conditionals in my example, and have this be available for bots and browsers that do not support javascript. The solution is to grab the geoip information serverside, and then generate the output in HTML using PHP.</p>
<p>To do this you will need to make sure that your version has the pecl-geoip extension available. I&#8217;m using <a href="http://pecl.php.net/geoip" target="_blank">dev-php5/pecl-geoip</a>. After this extension is built and is available to your PHP installation, you can simple call this geoip_record_by_name() function and pass a valid IP address.</p>
<p>For example, this is looking up a Google IP:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$record</span> = geoip_record_by_name<span class="br0">&#40;</span><span class="st0">&#8217;74.125.67.100&#8242;</span><span class="br0">&#41;</span>;<br />
<a href="http://www.php.net/var_dump"><span class="kw3">var_dump</span></a><span class="br0">&#40;</span><span class="re0">$record</span><span class="br0">&#41;</span>;</div>
<p>$record is a array that contains some useful information about that IP:</p>
<div class="dean_ch" style="white-space: wrap;"><a href="http://www.php.net/array"><span class="kw3">array</span></a><br />
<span class="st0">&#8216;country_code&#8217;</span> =&gt; string <span class="st0">&#8216;US&#8217;</span> <span class="br0">&#40;</span>length=<span class="nu0">2</span><span class="br0">&#41;</span><br />
<span class="st0">&#8216;region&#8217;</span> =&gt; string <span class="st0">&#8216;CA&#8217;</span> <span class="br0">&#40;</span>length=<span class="nu0">2</span><span class="br0">&#41;</span><br />
<span class="st0">&#8216;city&#8217;</span> =&gt; string <span class="st0">&#8216;Mountain View&#8217;</span> <span class="br0">&#40;</span>length=<span class="nu0">13</span><span class="br0">&#41;</span><br />
<span class="st0">&#8216;postal_code&#8217;</span> =&gt; string <span class="st0">&#8217;94043&#8242;</span> <span class="br0">&#40;</span>length=<span class="nu0">5</span><span class="br0">&#41;</span><br />
<span class="st0">&#8216;latitude&#8217;</span> =&gt; float <span class="nu0">37.4192008972</span><br />
<span class="st0">&#8216;longitude&#8217;</span> =&gt; float <span class="nu0">-122.057403564</span><br />
<span class="st0">&#8216;dma_code&#8217;</span> =&gt; int <span class="nu0">807</span><br />
<span class="st0">&#8216;area_code&#8217;</span> =&gt; int <span class="nu0">650</span></div>
<p>I had some problems with a missing GeoLiteCity.dat file that was missing. LiteCity is free, and any additional dats will cost money. Luckily, MaxMind had a download here: <a href="http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz" target="_blank">http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz</a></p>
<p>If you need function definitions, you can view them here. I was glad that I found this forum entry, pecl documentation and examples usually suck pretty bad:<br />
<a href="http://forum.maxmind.com/viewtopic.php?p=44" target="_blank">http://forum.maxmind.com/viewtopic.php?p=44</a></p>
<h4>Incoming search terms:</h4><ul><li>php webinar script</li><li>geoip js</li><li>geoip javascript</li><li>geoip js download</li><li>geo ip javascript</li><li>javascript geoip</li><li>j maxmind/app/geoip js</li><li>javascript geoip currency</li><li>geoip js vs php</li><li>geoip script</li></ul><div style='clear:both'></div>

<p>Related posts:<ol><li><a href='http://www.money-code.com/2009/07/monitor-your-sites-watch-your-logs/' rel='bookmark' title='Monitor your sites &#8211; Watch your logs'>Monitor your sites &#8211; Watch your logs</a></li>
<li><a href='http://www.money-code.com/2007/09/capture-search-data-on-your-site/' rel='bookmark' title='Capture search data on your site'>Capture search data on your site</a></li>
<li><a href='http://www.money-code.com/2008/01/problems-fetching-cj-product-feeds-with-phps-ftp-functionality/' rel='bookmark' title='Problems fetching CJ Product Feeds with PHP&#8217;s FTP functionality'>Problems fetching CJ Product Feeds with PHP&#8217;s FTP functionality</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.money-code.com/2009/06/geoip-scripts-php-and-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
