<?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>The html blog &#187; country</title>
	<atom:link href="http://htmlblog.net/tag/country/feed/" rel="self" type="application/rss+xml" />
	<link>http://htmlblog.net</link>
	<description>The web sandbox of Asvin Balloo</description>
	<lastBuildDate>Tue, 09 Nov 2010 11:39:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Geolocate your visitors with PHP (part 1)</title>
		<link>http://htmlblog.net/geolocate-your-visitors-with-php-part-1/</link>
		<comments>http://htmlblog.net/geolocate-your-visitors-with-php-part-1/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 15:04:31 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[country]]></category>
		<category><![CDATA[geoip]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[maxmind]]></category>
		<category><![CDATA[net]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=19</guid>
		<description><![CDATA[In this short post I&#8217;ll show you how to geolocate your visitors with PHP. First of all let&#8217;s have a look at what you&#8217;ll need : PEAR GeoIP MaxMind GeoLite Country Installing PEAR GeoIP Using your console or using the command prompt type : pear install http://download.pear.php.net/package/Net_GeoIP-1.0.0RC1.tgz Obtaining MaxMind GeoLite Country The database can be [...]]]></description>
			<content:encoded><![CDATA[<p>In this short post I&#8217;ll show you how to geolocate your visitors with <a href="http://php.net">PHP</a>. First of all let&#8217;s have a look at what you&#8217;ll need :</p>
<ul>
<li>PEAR GeoIP</li>
<li>MaxMind GeoLite Country</li>
</ul>
<p><span id="more-19"></span></p>
<h3>Installing PEAR GeoIP</h3>
<p>Using your console or using the command prompt type :</p>
<pre class="brush: bash">
pear install http://download.pear.php.net/package/Net_GeoIP-1.0.0RC1.tgz
</pre>
<h3>Obtaining MaxMind GeoLite Country</h3>
<p>The database can be <a href="http://www.maxmind.com/app/geoip_country">downloaded freely here</a>. Download it and put it in the same folder where your script will reside.<br />
<!--more--></p>
<h3>The code</h3>
<pre class="brush: php">
&lt;?php
	require_once(&#039;Net/GeoIP.php&#039;);

	$geoip = Net_GeoIP::getInstance(&#039;./GeoIP.dat&#039;);
	$ip = getenv(&#039;REMOTE_ADDR&#039;);
	$country = $geoip-&gt;lookupCountryName($ip);

	echo &quot;Hi, you&#039;re from &quot;.$country;
?&gt;
</pre>
<h3>Walkthrough</h3>
<p>Now let&#8217;s go through the lines of code. The first line  tells us to include the GeoIP class, which we installed previously and then create a geoip object in line 5 from the database we downloaded.<br />
Next, in line 6 we get the IP address of the visitor and finally we call the <a href="http://pear.php.net/manual/en/package.networking.net-geoip.lookupcountryname.php">lookupCountryName</a> method with the IP address as parameter in line 7 and it will return us the country. </p>
<p>The last line just outputs the country, for example,  &#8220;Hi, you&#8217;re from Mauritius&#8221;. That&#8217;s it, now you know where your visitor&#8217;s from.</p>
<p><a href="http://htmlblog.net/geolocate-your-visitors-with-php-part-2/">In the second part of this article</a> I&#8217;ll show you how to use the script to visually map your visitors using <a href="http://code.google.com/apis/maps/">Google Maps</a>. You can have a little <a href="http://htmlblog.net/demo/myip/">preview of the script here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/geolocate-your-visitors-with-php-part-1/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

