简体   繁体   中英

Prevent users from downloading files in a specific directory

My website is coded using PHP. Library files are stored in a directory called 'library'.

Within my php I access the library files by

require_once('library/myfile.php.inc'); 

However, if the user types in

http://www.example.com/library/myfile.php.inc

They are able to download the source code. How can I prevent this?

Create .htaccess file under root/library/.htaccess and write the following

<FilesMatch ".*">
    Order Allow,Deny
    Deny from All
</FilesMatch>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM