简体   繁体   中英

How can I protect files in a folder in a PHP site?

I'm using PHP. What I need is to protect the folder files from listing the file names when we enter the path for the folder.

http://test.com/admin/free_tmplt

This is my folder path and when I use this path directly it display the file names. How to avoid this and display a message like "Protected page"?

要只是阻止它们被列出(这不会保护文件的安全。但这是您提出的问题),只需在该文件夹中创建index.php。

在文件夹中创建一个.htacess文件,然后键入deny from all

您也可以这样做,以便该文件夹中的所有文件都具有随机的文件名,这些文件名会在人们加载某些页面等情况下定期更改(并且这些不断变化的文件名将存储在数据库中)-这样,没人会“猜测”或直接链接到文件,无论它们是否被隐藏。

You can create a file called (index.php) and put it in every folder you want to hide its contents (prevent them from being listed), and put the next line of code in that (index.php) file:

<?php header("Location: http://" . $_SERVER['HTTP_HOST']); ?>

as this line of code will redirect the user to homepage of the website.

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