<?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>Tim Showers - Web Development, Design, and Data Visualization &#187; PHP</title>
	<atom:link href="http://www.timshowers.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.timshowers.com</link>
	<description>Tutorials, Polemics, and Discussion about all things web-nerdy</description>
	<lastBuildDate>Mon, 18 May 2009 21:30:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Implementing HTTPOnly in PHP</title>
		<link>http://www.timshowers.com/2008/08/implementing-httponly-in-php/</link>
		<comments>http://www.timshowers.com/2008/08/implementing-httponly-in-php/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 23:55:35 +0000</pubDate>
		<dc:creator>Tim Showers</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.timshowers.com/?p=230</guid>
		<description><![CDATA[Coding Horror has an article today about a little-known extension to the http cookie protocol: HTTPOnly.
Essentially, HTTPOnly makes any browser cookies from the site unreadable to javascript (in supported browsers anyway: IE7, Opera 9.5, FF3), thus raising the bar for XSS attacks considerably.
So how do we turn it on in PHP?

If you&#8217;re using a version [...]]]></description>
			<content:encoded><![CDATA[<p>Coding Horror has an <a href="http://www.codinghorror.com/blog/archives/001167.html">article</a> today about a little-known extension to the http cookie protocol: <a href="http://msdn.microsoft.com/en-us/library/ms533046.aspx">HTTPOnly</a>.</p>
<p>Essentially, HTTPOnly makes any browser cookies from the site unreadable to javascript (in supported browsers anyway: IE7, Opera 9.5, FF3), thus raising the bar for <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">XSS</a> attacks considerably.</p>
<p>So how do we turn it on in PHP?<br />
<span id="more-230"></span></p>
<p>If you&#8217;re using a version of PHP pre5.2:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Set-Cookie: hidden=value; httpOnly&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If you&#8217;re using a new version of PHP (5.2+):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Either of these options set the $_SESSION cookie into HTTPOnly mode</span>
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;session.cookie_httponly&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// or</span>
<span style="color: #990000;">session_set_cookie_params</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Individual cookies can be set using:</span>
<span style="color: #990000;">setcookie</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;abc&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;test&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">//or</span>
<span style="color: #990000;">setrawcookie</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;abc&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;test&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And that&#8217;s it!<br />
One simple line of code (or function argument) that you can add to your header file that helps makes attacks on your site tougher to execute. </p>
<p>Code snippets courtesy of <a href="http://ilia.ws/archives/121-httpOnly-cookie-flag-support-in-PHP-5.2.html">Ilia Alshanetsky</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.timshowers.com/2008/08/implementing-httponly-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preventing Wordpress Post Updates from Changing RSS</title>
		<link>http://www.timshowers.com/2008/08/preventing-wordpress-post-updates-from-changing-rss/</link>
		<comments>http://www.timshowers.com/2008/08/preventing-wordpress-post-updates-from-changing-rss/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 16:02:01 +0000</pubDate>
		<dc:creator>Tim Showers</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress Hacks]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.timshowers.com/?p=129</guid>
		<description><![CDATA[A minor wordpress annoyance that i&#8217;ve run across lately is that every time you update a post, the date on the post changes, so it moves to the top of your RSS feed.  Thankfully, Ciaran Gultnieks has a solution.
]]></description>
			<content:encoded><![CDATA[<p>A minor wordpress annoyance that i&#8217;ve run across lately is that every time you update a post, the date on the post changes, so it moves to the top of your RSS feed.  Thankfully, <a title="Solution to Wordpress RSS Bug" href="http://blog.ciarang.com/posts/wordpress-minor-edits-hack/">Ciaran Gultnieks has a solution</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.timshowers.com/2008/08/preventing-wordpress-post-updates-from-changing-rss/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fixing escaping problems in WP-Syntax</title>
		<link>http://www.timshowers.com/2008/08/fixing-escaping-problems-in-wp-syntax/</link>
		<comments>http://www.timshowers.com/2008/08/fixing-escaping-problems-in-wp-syntax/#comments</comments>
		<pubDate>Sun, 03 Aug 2008 01:21:07 +0000</pubDate>
		<dc:creator>Tim Showers</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress Hacks]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.timshowers.com/?p=98</guid>
		<description><![CDATA[I&#8217;ve installed the WP-Syntax wordpress plugin for code highlighting, and am very impressed, except for a nasty bug that was causing code snippets to escape html special characters.
Thankfully Gergely Hodicska has a solution on his blog.
Hopefully this sees integration into the actual plugin&#8217;s codebase at some point.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve installed the <a href="http://wordpress.org/extend/plugins/wp-syntax/">WP-Syntax</a> wordpress plugin for code highlighting, and am very impressed, except for a nasty bug that was causing code snippets to escape html special characters.</p>
<p>Thankfully <a href="http://blog.felho.hu/escaping-problem-with-wp-syntax-wordpress-plugin.html">Gergely Hodicska</a> has a solution on his blog.</p>
<p>Hopefully this sees integration into the actual plugin&#8217;s codebase at some point.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.timshowers.com/2008/08/fixing-escaping-problems-in-wp-syntax/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Geocoding tutorial with the Google Maps API &#8211; Part One</title>
		<link>http://www.timshowers.com/2008/08/php-geocoding-tutorial-with-the-google-maps-api-part-one/</link>
		<comments>http://www.timshowers.com/2008/08/php-geocoding-tutorial-with-the-google-maps-api-part-one/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 16:49:30 +0000</pubDate>
		<dc:creator>Tim Showers</dc:creator>
				<category><![CDATA[Geocoding & Mapping]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Geocoding]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.timshowers.com/?p=85</guid>
		<description><![CDATA[So unless you live under a non-Web 2.0-enabled rock, you&#8217;ve probably heard of the magic of the Google maps API and google maps mashups. If you&#8217;re saavy, you&#8217;ve probably even heard that now Google Maps offer translation of addresses into latitude and longitude, aka Geocoding. 
What you may not know is that the folks at [...]]]></description>
			<content:encoded><![CDATA[<p>So unless you live under a non-Web 2.0-enabled rock, you&#8217;ve probably heard of the magic of the Google maps API and google maps mashups. If you&#8217;re saavy, you&#8217;ve probably even heard that now Google Maps offer translation of addresses into latitude and longitude, aka Geocoding. </p>
<p>What you may not know is that the folks at google exposed this geocoding as a regular old URL-based webservice, which means that whatever Nifty mashups your devious little minds can come up with (as long as they fly with google&#8217;s TOS) can be powered on the backend without ever loading a google map!<br />
<span id="more-85"></span><br />
So lets cut the chit-chat and jump to some code&#8230; I&#8217;m going to use PHP here, but do whatever fuels your nerding.</p>
<p>First, <a href="http://code.google.com/apis/maps/signup.html">sign up</a> for a key, put in whatever URL you happen to own, it won&#8217;t matter (i&#8217;ll explain later).</p>
<p>next, add this to your php file, making SURE to replace the key with your own:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #666666; font-style: italic;">//Three parts to the querystring: q is address, output is the format, key is the GAPI key</span>
<span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;YOUR KEY HERE&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$address</span> <span style="color: #339933;">=</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;columbia MO&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//If you want an extended data set, change the output to &quot;xml&quot; instead of csv</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://maps.google.com/maps/geo?q=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$address</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;output=csv&amp;key=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Set up a CURL request, telling it not to spit back headers, and to throw out a user agent.</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Change this to a 1 to return headers</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_USER_AGENT&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Data: &quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Supposing all goes well you should see the following: (if not check the PHP CURL manual)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Data<span style="color: #339933;">:</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color:#800080;">38.951667</span><span style="color: #339933;">,-</span><span style="color:#800080;">92.333889</span></pre></div></div>

<p>You&#8217;ll notice that the first number is the return code, the second the relative accuracy (there 4 we see here is quite low as a result of the broad input. 8 is street-level address accuracy), third the latitude, and fourth the longitude.</p>
<p>So now that we&#8217;ve seen the magic.. let&#8217;s get it all nicely formatted:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Check our Response code to ensure success</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;200&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$precision</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$latitude</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$longitude</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Error in geocoding! Http error &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And that&#8217;s it! Less than 40 lines of code to give you a powerful resource for mapping and usability. Just how powerful? You&#8217;ll have to wait for part two to find out&#8230;</p>
<p>*Note on locations and API keys: In my experience thus far, the Geocoding service doesn&#8217;t actually check that the api key is being called from the originating server. This may change in the future at some point, so keep your eyes open.<br />
FULL CODE LISTING:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #666666; font-style: italic;">//Set up our variables</span>
<span style="color: #000088;">$longitude</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$latitude</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$precision</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Three parts to the querystring: q is address, output is the format (</span>
<span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;YOUR KEY HERE&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$address</span> <span style="color: #339933;">=</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;columbia MO&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://maps.google.com/maps/geo?q=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$address</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;amp;output=csv&amp;amp;key=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_USER_AGENT&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Data: &quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$data</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;lt;br&amp;gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Check our Response code to ensure success</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;200&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$precision</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$latitude</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$longitude</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Latutide: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$latitude</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;lt;br&amp;gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Longitude: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$longitude</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;lt;br&amp;gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Error in geocoding! Http error &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>Update:</h4>
<p>A few people have mentioned that after some number of requests (between 100-300) in quick succession google will kill your access for the day, so you may want to insert a</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To stagger the requests a little.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.timshowers.com/2008/08/php-geocoding-tutorial-with-the-google-maps-api-part-one/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
