<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Protecting a download using a unique URL</title>
	<atom:link href="http://www.ardamis.com/2008/06/11/protecting-a-download-using-a-unique-url/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ardamis.com/2008/06/11/protecting-a-download-using-a-unique-url/</link>
	<description>Ardamis is a tiny web development studio specializing in high-quality, handmade web sites.</description>
	<lastBuildDate>Sat, 20 Mar 2010 17:30:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Vincent</title>
		<link>http://www.ardamis.com/2008/06/11/protecting-a-download-using-a-unique-url/#comment-29507</link>
		<dc:creator>Vincent</dc:creator>
		<pubDate>Sun, 14 Mar 2010 12:10:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.ardamis.com/?p=68#comment-29507</guid>
		<description>hey everyone i just wanted to show my implementation of this code for my bands music.

Site: http://download.soundmilitia.com/index3.html 
Download Code: ardamis

*note the code will only work on the above URL and not on the base site.

and also try using a fake code such as: Apples or  15d6as17f8afd178a6</description>
		<content:encoded><![CDATA[<p>hey everyone i just wanted to show my implementation of this code for my bands music.</p>
<p>Site: <a href="http://download.soundmilitia.com/index3.html" rel="nofollow">http://download.soundmilitia.com/index3.html</a><br />
Download Code: ardamis</p>
<p>*note the code will only work on the above URL and not on the base site.</p>
<p>and also try using a fake code such as: Apples or  15d6as17f8afd178a6</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent</title>
		<link>http://www.ardamis.com/2008/06/11/protecting-a-download-using-a-unique-url/#comment-29449</link>
		<dc:creator>Vincent</dc:creator>
		<pubDate>Sat, 13 Mar 2010 13:09:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.ardamis.com/?p=68#comment-29449</guid>
		<description>i also forgot.. after you run that gen.php file

you can go to your database manager and export it for excel. then use that for mail merge in Microsoft office publisher on say a business card. :)</description>
		<content:encoded><![CDATA[<p>i also forgot.. after you run that gen.php file</p>
<p>you can go to your database manager and export it for excel. then use that for mail merge in Microsoft office publisher on say a business card. <img src='http://www.ardamis.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent</title>
		<link>http://www.ardamis.com/2008/06/11/protecting-a-download-using-a-unique-url/#comment-29448</link>
		<dc:creator>Vincent</dc:creator>
		<pubDate>Sat, 13 Mar 2010 13:05:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.ardamis.com/?p=68#comment-29448</guid>
		<description>RLBO,   i found this to work for your purpose. i am using it to create download cards for my music and other stuff.

it can generate a code with however many you need

&lt;?php
// A script to generate unique download keys for the purpose of protecting downloadable goods

require (&#039;dbconnect.php&#039;);

	if(empty($_SERVER[&#039;REQUEST_URI&#039;])) {
    	$_SERVER[&#039;REQUEST_URI&#039;] = $_SERVER[&#039;SCRIPT_NAME&#039;];
	}

	// Strip off query string so dirname() doesn&#039;t get confused
	$url = preg_replace(&#039;/\?.*$/&#039;, &#039;&#039;, $_SERVER[&#039;REQUEST_URI&#039;]);
	$folderpath = &#039;http://&#039;.$_SERVER[&#039;HTTP_HOST&#039;].&#039;/&#039;.ltrim(dirname($url), &#039;/&#039;).&#039;/&#039;;




// Function to generate a 10 digit alpha-numeric code

function randomPrefix($length)
{
$random= &quot;&quot;;

srand((double)microtime()*1000000);

$data = &quot;AbcDE123IJKLMN67QRSTUVWXYZ&quot;;
$data .= &quot;aBCdefghijklmn123opq45rs67tuv89wxyz&quot;;
$data .= &quot;0FGH45OP89&quot;;

for($i = 0; $i &lt; $length; $i++)
{
$random .= substr($data, (rand()%(strlen($data))), 1);
}

return $random;
}



	
// Generate the link
	echo &quot;Here are the download keys&quot;;

	
$i = 1;
while ($i &lt;= 10) {
 $i++;
 
// $random = randomPrefix(MUMBER OF CHARACTERS DESIRED);
$random = randomPrefix(10);
$time = date(&#039;U&#039;);

//print the codes to page
echo &quot;&quot;. $random. &quot;&quot;;
   
//sends codes to Database
$registerid = mysql_query(&quot;INSERT INTO downloadkey (uniqueid,timestamp) VALUES(\&quot;$random\&quot;,\&quot;$time\&quot;)&quot;) or die(mysql_error());
	
	
}

?&gt;</description>
		<content:encoded><![CDATA[<p>RLBO,   i found this to work for your purpose. i am using it to create download cards for my music and other stuff.</p>
<p>it can generate a code with however many you need</p>
<p>&lt;?php<br />
// A script to generate unique download keys for the purpose of protecting downloadable goods</p>
<p>require (&#039;dbconnect.php&#039;);</p>
<p>	if(empty($_SERVER[&#039;REQUEST_URI&#039;])) {<br />
    	$_SERVER[&#039;REQUEST_URI&#039;] = $_SERVER[&#039;SCRIPT_NAME&#039;];<br />
	}</p>
<p>	// Strip off query string so dirname() doesn&#039;t get confused<br />
	$url = preg_replace(&#039;/\?.*$/&#039;, &#039;&#039;, $_SERVER[&#039;REQUEST_URI&#039;]);<br />
	$folderpath = &#039;http://&#039;.$_SERVER[&#039;HTTP_HOST&#039;].&#039;/&#039;.ltrim(dirname($url), &#039;/&#039;).&#039;/&#039;;</p>
<p>// Function to generate a 10 digit alpha-numeric code</p>
<p>function randomPrefix($length)<br />
{<br />
$random= &quot;&quot;;</p>
<p>srand((double)microtime()*1000000);</p>
<p>$data = &quot;AbcDE123IJKLMN67QRSTUVWXYZ&quot;;<br />
$data .= &quot;aBCdefghijklmn123opq45rs67tuv89wxyz&quot;;<br />
$data .= &quot;0FGH45OP89&quot;;</p>
<p>for($i = 0; $i &lt; $length; $i++)<br />
{<br />
$random .= substr($data, (rand()%(strlen($data))), 1);<br />
}</p>
<p>return $random;<br />
}</p>
<p>// Generate the link<br />
	echo &quot;Here are the download keys&#8221;;</p>
<p>$i = 1;<br />
while ($i &lt;= 10) {<br />
 $i++;</p>
<p>// $random = randomPrefix(MUMBER OF CHARACTERS DESIRED);<br />
$random = randomPrefix(10);<br />
$time = date(&#039;U&#039;);</p>
<p>//print the codes to page<br />
echo &quot;&#8221;. $random. &#8220;&#8221;;</p>
<p>//sends codes to Database<br />
$registerid = mysql_query(&#8220;INSERT INTO downloadkey (uniqueid,timestamp) VALUES(\&#8221;$random\&#8221;,\&#8221;$time\&#8221;)&#8221;) or die(mysql_error());</p>
<p>}</p>
<p>?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Roijers</title>
		<link>http://www.ardamis.com/2008/06/11/protecting-a-download-using-a-unique-url/#comment-28961</link>
		<dc:creator>Tim Roijers</dc:creator>
		<pubDate>Thu, 04 Mar 2010 16:19:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.ardamis.com/?p=68#comment-28961</guid>
		<description>Cool script, but when i open the link de browser opens the zipfile in de browser instead of presenting a save as window. Any idea how to fix this?</description>
		<content:encoded><![CDATA[<p>Cool script, but when i open the link de browser opens the zipfile in de browser instead of presenting a save as window. Any idea how to fix this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Muthuraman</title>
		<link>http://www.ardamis.com/2008/06/11/protecting-a-download-using-a-unique-url/#comment-25951</link>
		<dc:creator>Muthuraman</dc:creator>
		<pubDate>Tue, 12 Jan 2010 04:31:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.ardamis.com/?p=68#comment-25951</guid>
		<description>hello ardamis 


its really Good script for beginner 


$url = preg_replace(&#039;/\?.*$/&#039;, &#039;&#039;, $_SERVER[&#039;REQUEST_URI&#039;]);
$folderpath = &#039;http://&#039;.$_SERVER[&#039;HTTP_HOST&#039;].&#039;/&#039;.ltrim(dirname($url), &#039;/&#039;).&#039;/&#039;;

can you tell me how to give the path url to file</description>
		<content:encoded><![CDATA[<p>hello ardamis </p>
<p>its really Good script for beginner </p>
<p>$url = preg_replace(&#8216;/\?.*$/&#8217;, &#8221;, $_SERVER['REQUEST_URI']);<br />
$folderpath = &#8216;http://&#8217;.$_SERVER['HTTP_HOST'].&#8217;/&#8217;.ltrim(dirname($url), &#8216;/&#8217;).&#8217;/';</p>
<p>can you tell me how to give the path url to file</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Stollaire</title>
		<link>http://www.ardamis.com/2008/06/11/protecting-a-download-using-a-unique-url/#comment-25776</link>
		<dc:creator>Michael Stollaire</dc:creator>
		<pubDate>Thu, 07 Jan 2010 19:30:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.ardamis.com/?p=68#comment-25776</guid>
		<description>This is an incredible piece of code, and thanks so much, as a client was looking for just this very thing.

Once the download key is generated, instead of posting this, can we redirect the output from a form to an email, so the user gets an email with the unique download link?

Thanks!

~ Michael</description>
		<content:encoded><![CDATA[<p>This is an incredible piece of code, and thanks so much, as a client was looking for just this very thing.</p>
<p>Once the download key is generated, instead of posting this, can we redirect the output from a form to an email, so the user gets an email with the unique download link?</p>
<p>Thanks!</p>
<p>~ Michael</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ann</title>
		<link>http://www.ardamis.com/2008/06/11/protecting-a-download-using-a-unique-url/#comment-24428</link>
		<dc:creator>Ann</dc:creator>
		<pubDate>Fri, 04 Dec 2009 21:09:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.ardamis.com/?p=68#comment-24428</guid>
		<description>Great script! Thank you!

I have an issue with the download file. Everything works perfectly until I open up the downloaded file. The zip file attached is empty.

Does it support other file formats (e.g. PDFs)?

Thanks for your help.</description>
		<content:encoded><![CDATA[<p>Great script! Thank you!</p>
<p>I have an issue with the download file. Everything works perfectly until I open up the downloaded file. The zip file attached is empty.</p>
<p>Does it support other file formats (e.g. PDFs)?</p>
<p>Thanks for your help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gerard</title>
		<link>http://www.ardamis.com/2008/06/11/protecting-a-download-using-a-unique-url/#comment-20289</link>
		<dc:creator>Gerard</dc:creator>
		<pubDate>Tue, 15 Sep 2009 16:14:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.ardamis.com/?p=68#comment-20289</guid>
		<description>Thank you very much for your code.

However, I have the following problem: When I put the URL in the address bar to get the file, it is open as text instead of appearing the menu to save it. I&#039;m using Firefox on Debian Lenny and I have verified that the file is a standard zip file.

I would appreciate any suggestion.</description>
		<content:encoded><![CDATA[<p>Thank you very much for your code.</p>
<p>However, I have the following problem: When I put the URL in the address bar to get the file, it is open as text instead of appearing the menu to save it. I&#8217;m using Firefox on Debian Lenny and I have verified that the file is a standard zip file.</p>
<p>I would appreciate any suggestion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nate</title>
		<link>http://www.ardamis.com/2008/06/11/protecting-a-download-using-a-unique-url/#comment-20272</link>
		<dc:creator>Nate</dc:creator>
		<pubDate>Tue, 15 Sep 2009 11:07:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.ardamis.com/?p=68#comment-20272</guid>
		<description>Actually, it eventually does download the file, not a blank file. It takes probably 2 minutes though after pressing &quot;Go&quot; for the download link. Also, please ignore the download rate comment in the code above; I meant to change the 8.5kb/s.</description>
		<content:encoded><![CDATA[<p>Actually, it eventually does download the file, not a blank file. It takes probably 2 minutes though after pressing &#8220;Go&#8221; for the download link. Also, please ignore the download rate comment in the code above; I meant to change the 8.5kb/s.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nate</title>
		<link>http://www.ardamis.com/2008/06/11/protecting-a-download-using-a-unique-url/#comment-20256</link>
		<dc:creator>Nate</dc:creator>
		<pubDate>Tue, 15 Sep 2009 06:41:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.ardamis.com/?p=68#comment-20256</guid>
		<description>I found the following code to be able to limit the download speed:

&lt;code&gt;
&lt;?php
  
 $file = &quot;Windows_Vista_Ultimate_x86_OEM.iso&quot;; // file to be send to the client
 $speed = 500;  // 8,5 kb/s download rate limit
  
 if(file_exists($file) &amp;&amp; is_file($file)) {
  
    header(&quot;Cache-control: private&quot;);
    header(&quot;Content-Type: application/octet-stream&quot;); 
    header(&quot;Content-Length: &quot;.filesize($file));
    header(&quot;Content-Disposition: filename=$file&quot; . &quot;%20&quot;); 
  
    flush();
  
    $fd = fopen($file, &quot;r&quot;);
    while(!feof($fd)) {
          echo fread($fd, round($speed*1024));
        flush();
        sleep(1);
    }
    fclose ($fd);
  
 }
 ?&gt;
&lt;/code&gt;

How can I incorporate this code into download.php? I&#039;m not very PHP savvy but I&#039;ve tried several ways to include it. Two ways I did it didn&#039;t cause any script errors but when when trying to access the random link, it just tries and tries. Browser says &quot;waiting website.com&quot; on the bottom left corner. Eventually, it gives a download prompt but it just downloads a blank file. Any ideas?

Thanks in advance.</description>
		<content:encoded><![CDATA[<p>I found the following code to be able to limit the download speed:</p>
<p></p><pre><code>
&lt;?php
  
 $file = "Windows_Vista_Ultimate_x86_OEM.iso"; // file to be send to the client
 $speed = 500;  // 8,5 kb/s download rate limit
  
 if(file_exists($file) &amp;&amp; is_file($file)) {
  
    header("Cache-control: private");
    header("Content-Type: application/octet-stream"); 
    header("Content-Length: ".filesize($file));
    header("Content-Disposition: filename=$file" . "%20"); 
  
    flush();
  
    $fd = fopen($file, "r");
    while(!feof($fd)) {
          echo fread($fd, round($speed*1024));
        flush();
        sleep(1);
    }
    fclose ($fd);
  
 }
 ?&gt;
</code></pre><p></p>
<p>How can I incorporate this code into download.php? I&#8217;m not very PHP savvy but I&#8217;ve tried several ways to include it. Two ways I did it didn&#8217;t cause any script errors but when when trying to access the random link, it just tries and tries. Browser says &#8220;waiting website.com&#8221; on the bottom left corner. Eventually, it gives a download prompt but it just downloads a blank file. Any ideas?</p>
<p>Thanks in advance.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
