Page 1 of 1

Beginner: How to Limit Downloads

Posted: Mon Jun 15, 2009 4:45 am
by jal
I have a new website hosted by Yahoo Webhosting. I think they only support PHP scripting. (To date I've only done a little vbscript and even less javascript).

I want to make my MP3 files downloadable. Many sites limit downloads by showing the user distorted letters which he has to read and then type in. I don't know what this is called, much less how to set it up.

Should I be using PHP for this? If so, can someone give me some keywords to help me google for some articles on how to code this?

Or is there an easier way to set this up?

Re: Beginner: How to Limit Downloads

Posted: Mon Jun 15, 2009 4:52 am
by miro_igov
You talk about captcha.

Re: Beginner: How to Limit Downloads

Posted: Mon Jun 15, 2009 12:01 pm
by Patrick Latour
I will post the code of something I did. Very simple, but work very well. I will be back to the office in a couple of hours, I will post it as soon as I will be there.

Re: Beginner: How to Limit Downloads

Posted: Mon Jun 15, 2009 5:50 pm
by Patrick Latour
Ok, I am back, here is the my receipt:

1-) First, using photoshop, I made 10 small images of 30 pixels by 30 pixels. In them I place a number from 0 to 9 and I added some noise to make them more difficult to read. Pictures are named based on the number the represent: 0.gif for the number 0, 1.gif for the number 1 and so on.

2-) Second, I placed this code. A couple of things to note: I execute a 5 times loop to generate 4 random numbers between 0 and 9, I concaten them to build a 4 digits number, hold in the variable $confirmCode. I show 4 pictures representing the 4 random number. I passed the variable in an hidden field to compare with the entry the user did in an input box (not shown in my code). I hope this help.

Code: Select all

 
 
// We loop 4 times, but it could be as long or short as you want
//-----------------------------------------------------------
for ($i=1;$i<5;$i++)
{
   // We get a random number between 0 and 9
   //-----------------------------------------
    mt_srand((double)microtime()*1000000);
    $code=mt_rand(0,9);
   
   // We show the corresponding gif
   //------------------------------
    echo "<img src=\"images/".$code.".gif\" alt=\"\"></img>\n";
 
   // We register the 4 digits number to later compare with the user's answer    
   //---------------------------------------------------------------------
   $confirmCode.=$code;
}
 
echo "\n<input type=\"hidden\" name=\"confirmCode\" value=\"".$confirmCode."\" />\n";
 
Here is how it looks, sorry the site is in French, but you should be able to figure what I explained:
Image2.jpg
Image2.jpg (10 KiB) Viewed 451 times

Re: Beginner: How to Limit Downloads

Posted: Mon Jun 15, 2009 6:07 pm
by jal
Wow, thanks so much for the help!

I'll give it a whirl, but I think I'm getting in over my head. For a couple of years I tried to learn some programming (Visual Basic .Net and C# and VBA) but I never got very good with it and no one ever hired me. Moreover I have health problems, which makes it difficult for me to try to take on YET another programming language (I'm pretty burned out).

I was playing around with the code here:
http://www.encaps.net/software/php-captcha/

The user form came up okay but the actual captcha image didn't generate. (I don't know if Yahoo has the necessary graphics library installed).

PHP seems to be radically different in syntax than other languages I've studied.

Re: Beginner: How to Limit Downloads

Posted: Mon Jun 15, 2009 6:10 pm
by califdon
You can find dozens, if not hundreds of snippets, many that do not require creating your own images. Just Google "captcha". Be aware that nowadays, many bots can defeat captcha schemes. There are also some that use audio, etc. It's a matter of how much effort you want to put into something that is never going to be 100% effective. Still you can avoid some bots. But I wouldn't call it "limiting downloads" because what it does is attempt to insure that the requester is a live human being, not a bot program.

Re: Beginner: How to Limit Downloads

Posted: Mon Jun 15, 2009 7:07 pm
by jal
I suppose what I'll do is redirect the visitor to my download page once he types in the correct code.

How do I redirect him?

Re: Beginner: How to Limit Downloads

Posted: Mon Jun 15, 2009 7:11 pm
by jal
Ok, I found some sample redirect code.

Re: Beginner: How to Limit Downloads

Posted: Mon Jun 15, 2009 7:38 pm
by Patrick Latour
Another way that I found really interesting, I saw this technique on the Ubuntu forums, it is to ask a really obvious question, like:

1-) What color is an orange

2-) How many ears does have an average human


You can place 4 or 5 random questions in an array with their answer, and use it to verify is you are working with a human or not. It does not involve any graphic library or any mysterious and dark methods.

Good luck !!!

Re: Beginner: How to Limit Downloads

Posted: Mon Jun 15, 2009 8:01 pm
by jal
"What color is an orange? "

Excellent tip. I like this idea much better than captcha. Thanks !