Wednesday, November 25, 2009

Limit Download Files with PHP Script

ne of the problems a web developer is when trying to narrow down the download. Restricted download here is not intended as bandwidth management as practiced by a computer network administrator. But the restriction is limiting the download here is the only user who has registered only allowed to download. Problems surfaced when the browser displays the original location of the file storage directory. Of course the script has been created to be in vain.

Another problem related to downloading again there are restrictions on when users use download manager. Www.pdfchm.com samples can be taken.

More recently the author also has a few questions. How to do a good preventive so that only the registered users are welcome to download. Understandably, many real pendownload never desperate to figure out how to download a good. : D ~ ~ Including the author's own. : D ~ ~

Some of the last time the author tries to assemble a script to provide solutions that all. What is amazing in it have included prevention solutions downloaded by Download Manager like IDM, Download Accelerator Plus, download manager and many others. : D ~ ~
There is only a user to get used to the html file to download using a download manager. : D ~ ~ Mad indeed pendownload side. But the advantage for us. Can at least minimize the problems that exist.
Yupsss ... of the authors do not speak alone karuan, better describe the author directly about how sedetil may download the php restrictions.

Below is an example that the author made to explain how this script work.

The first is the index.php file will not explain the author of this script, because quite familiar.

The Registration and payment are duitnya ...: D ~~~


Kalo mau ngetest browsers that do not pay at first sessionnya clear ...

Tailor download but do not pay, gw banget: D ~~~ ";

?>

Second is reg.php file. The author if this script is a state when the user has been registered and will download the desired file.
The following form displays a security code. Users are welcome to fill out your name, email and code that has been provided. If conditions are met then the user is allowed to do the download. If not users will diredirect to redirect.php page.


align=center>



Name




Email






$ codenya


Codenya








";

?>

Few authors explain the above script. There is a function and one form.
Function is generateCode () ...

$ codenya = generateCode ();

This function is taken from code.php file, its contents are as follows:



Function is only randomization process numbers and letters. Possible letters and numbers-how many bits to be displayed can be set as you wish.
Sentence point is:

while ($ i <$ characters) ( $ code .= substr ($ possible, mt_rand (0, strlen ($ possible) -1), 1); $ i + +; ) This means, do all the randomization process n $ characters by using the variable $ possible as a possibility. You can use the logic of your property to conduct randomization process. This just as an example of randomization process that will be used as a security code. Return to the page reg.php $ _SESSION [ 'Code'] = $ codenya; $ _SESSION [ 'Download'] = session_id (); $ _SESSION [ 'Cekdownload'] = $ _SESSION [ 'download']; $ _SESSION [ 'Code'] will be used as a benchmark for matching with the variable $ _POST [ 'code']. Variable $ _POST [ 'code'] generated from the text itself Inputan named 'code' is entered by the user when filling out the form Inputan. $ _SESSION [ 'Download'] obtained from session_id (), here the authors use when the user has logged conditions. And will also be used to grant permission has only registered users are welcome to download. $ _SESSION [ 'Cekdownload'], authors use this session variable for confirmation only. Then cek.php file contains: This script works to filter: if (isset ($ _POST [ 'name']) & & isset ($ _POST [ 'email']) & & isset ($ _POST [ 'code'])) when the user has successfully entered the name, email and security code if ($ _SESSION [ 'code'] == $ _POST [ 'code']) and if the user has correctly filled the security codenya header ( "location: download.php / true / $ _SESSION [download]") the user will be redirect to download the file. and sentence else (echo "Security Codenya Wrong!!";) occurs because the user of filling code. Then the point is download.php script: to the browser header ( 'Content-Disposition: attachment; filename ='. $ fileName); header ( 'content-type:'. $ MimeType); header ( 'content-length:'. filesize ($ fileName)); / / Display the file readfile ($ fileName); ) else (header ( "location: redirect");) ?>

There is a sentence like this:
if (isset ($ _SESSION [ 'download']) & & ($ _SESSION [ 'download'] == $ _SESSION [ 'cekdownload']))
as the authors say, is just selecting it, I did it deliberately selecting repeatedly because basically the core of this script in a different page with the page when a new user successfully logged. This script so that became the backbone. His job is to trick the browser by giving special header. Thus although the previous user has to download, and provide a link like this:

http://www.victim.com/download.php/true/80261996fc7a35138de58216ac02a78a

to her friend to download while the user is already registered sessionnya has expired, only users who have not registered the diredirect to pages that make things more quiet and the mortal world. : D ~ ~

In my example script gives this sentence is in the file redirect.php

Kalo mau Download
Pay Donk ...
huehuheu: D ~ ~ ";
?>

back to the core of this script, which download.php

this sentence:

if (strpos ($ _SERVER [ 'HTTP_USER_AGENT'], 'MSIE 5') or
strpos ($ _SERVER [ 'HTTP_USER_AGENT'], 'Opera 7')) (
$ MimeType = 'application / x-download';
)

Actually, just to prevent bad habits conducted by the two browsers when reading a file type.

Next:
header ( 'Content-Disposition: attachment; filename ='. $ fileName);
header ( 'content-type:'. $ MimeType);
header ( 'content-length:'. filesize ($ fileName));
/ / Display the file
readfile ($ fileName);

first
header ( 'Content-Disposition: attachment; filename ='. $ fileName);

content-disposition header is ordered to treat the file browser that we put in hosting directory as a file that you downloaded.
content-type header, this is sometimes deliberately used as both a browser that is opera and internet explorer again failed to recognize the file type. Keep informed many times indeed. Bandelll! : D ~ ~ ~ huehue. (Hence dong pake mozilla firefox: D ~)

header ( 'content-length:'. filesize ($ fileName)); sentence serves to tell how big the file will be downloaded, so that when the browser to download the user can see the progress bar how much percent of the files being downloaded.

The latter is readfile ($ fileName);, because the previous headers have been introduced to the browser that this file of type zip, has a size so as well have told the browser to recognize that the file which will download it as a complement readfile for reading files will be downloaded, it is technically only displays the dialog form download.

Do not miss any writer create a file. Htaccess file to redirect.
Only served to equalize the same with http://www.victim.com/redirect.php http://www.victim.com/download.php/true/redirect.
So do not forget to activate your mod_rewite.

To enable mod_rewrite, you can edit the httpd.conf file to remove the sign # in line

# LoadModule rewrite_module modules / mod_rewrite.so

thus becomes

Rewrite_module LoadModule modules / mod_rewrite.so

Good luck.
The full script can be downloaded here http://www.networkandgame.890m.com/ilmuwebsite/labdownload.zip


No comments:

Post a Comment