<?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>brantheory &#187; programming</title>
	<atom:link href="http://www.brantheory.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brantheory.com</link>
	<description>theory of a living man</description>
	<lastBuildDate>Tue, 17 Feb 2009 21:42:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google Map Tip: Prevent direct linking to your XML data</title>
		<link>http://www.brantheory.com/2009/02/13/google-map-tip-prevent-direct-linking-to-your-xml-data/</link>
		<comments>http://www.brantheory.com/2009/02/13/google-map-tip-prevent-direct-linking-to-your-xml-data/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 05:08:55 +0000</pubDate>
		<dc:creator>bran</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.brantheory.com/?p=169</guid>
		<description><![CDATA[I have been recently working on a project integrating Google Maps API. It&#8217;s pretty straight forward and Google provides an excellent documention.  After working with the API and developing the custom mapping application, I noticed that the implemention exposes the name of the data file (xml, csv, text, etc) in the JavaScript code, example below [...]]]></description>
			<content:encoded><![CDATA[<p>I have been recently working on a project integrating <a href="http://code.google.com/apis/maps/">Google Maps API</a>. It&#8217;s pretty straight forward and Google provides an excellent documention.  After working with the API and developing the custom mapping application, I noticed that the implemention exposes the name of the data file (xml, csv, text, etc) in the JavaScript code, example below (can be seen by viewing page source):</p>
<pre>        <strong>GDownloadUrl("address.xml", function(data) {</strong>
...
)}</pre>
<p>Notice the bold area. &#8220;address.xml&#8221; is the file that contains all the xml data that has been collected and organized. I can pretty much download the file by entering in my address bar:  http://root url/address.xml. Voila, I have basically ripped off someone else&#8217;s data to be used as I see fit. Perhaps to create my own map!</p>
<p>I personally do not want to expose the location of my data file and allow others to download it.  To get around this issue, I have implemented a simple solution.</p>
<p>Rather than &#8220;address.xml&#8221;, I have created a new separate .php file. Let&#8217;s call it address.php. In that file, I check the referrer information to ensure that the request comes from the proper location. If it does, write the xml contents. If not, redirect them somewhere else.</p>
<pre>&lt;?php

    // prevent direct linking to xml files

 if($_SERVER['HTTP_REFERER'] != '') {

          $xml_string = file_get_contents("xml_location/address.xml");

        echo $xml_string;  

 }else{    
     // redirect them somewhere if they try to direct link to this page
      header( 'Location: http://www.google.com' ) ;

 }

?&gt;</pre>
<p>For the Google map, replace xml file with php file<strong> </strong></p>
<p>GDownloadUrl(&#8220;<strong>address.xml</strong>&#8220;, function(data) {  to:  GDownloadUrl(&#8220;<strong>address.php</strong>&#8220;, function(data) {</p>
<p>Simple as that. So if a curious viewer decides to enter &#8220;address.php&#8221; into there browser, they won&#8217;t get any data, just be redirected to some location you decide on.</p>
<p>There are also other ways to do this but IMO this is probably the simplilest and most effective.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brantheory.com/2009/02/13/google-map-tip-prevent-direct-linking-to-your-xml-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
