How to prohibit directory listing in php

PHPz
Release: 2023-03-05 21:50:02
Original
2701 people have browsed it

How to prohibit directory listing in php: first find and open the "httpd.conf" file; then add the "–" symbol in front of "Indexes" in "Options Indexes FollowSymLinks"; finally save the changes.

How to prohibit directory listing in php

Recommended: "PHP Video Tutorial"

Configuration method to disable display of directory file list in Apache

If you enter the address of a virtual directory: http://localhost:8080/b/

If there is no index.html in the virtual directory, the browser will also display the directory structure of the virtual directory. List the files and subdirectories under this virtual directory.

How to prevent Apache from displaying directory listing?

To prevent Apache from displaying the directory structure list, just remove Indexes in Option.

For example, let’s take a look at the directory configuration of a directory:

<Directory "D:/Apa/blabla">
    Options Indexes FollowSymLinks #----------> Options  FollowSymLinks AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
Copy after login

You only need to remove Indexes in the red code above to prevent Apache from displaying the directory structure. The user will not see the list of files and subdirectories in this directory.

The function of Indexes is to display the directory structure when there is no index.html file in the directory. If Indexes is removed, Apache will not display the list of the directory.

If set like this, the directory list may still be displayed:

<Directory / >
    Options  FollowSymLinks AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
Copy after login

Second method

Edit the httpd.conf file Edit the httpd.conf file

vi ./conf/httpd.conf
Copy after login

Find the following content:

……
<Directory “C:/Program Files/Apache2.2/htdocs”>
    #
    # Possible values for the Options directive are “None”, “All”,
    # or any combination of:
     Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that “MultiViews” must be named *explicitly* — “Options All”
    # doesn’t give it to you.
    #
    # The Options directive is both complicated and important. Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be “All”, “None”, or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None
    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all
</Directory>
……
Copy after login

Add the – symbol in front of Indexes in Options Indexes FollowSymLinks.

That is: Options -Indexes FollowSymLinks

[Note: before Indexes, adding means allowing directory browsing; adding – means prohibiting directory browsing. 】

In this case, the entire Apache prohibits directory browsing.

If it is in a virtual host, just add the following information:

<Directory “D:\test”>
     Options -Indexes FollowSymLinks
     AllowOverride None
     Order deny,allow
     Allow from all
</Directory>
Copy after login

In this case, directory browsing under the test project is prohibited.

Note: Remember not to change "Allow from all" to "Deny from all", otherwise, the entire website cannot be opened.

There is another method:

You can enter

<Files *>
Options -Indexes
</Files>
Copy after login

in the .htaccess file in the root directory to prevent Apache from listing the directory structure.

The above is the detailed content of How to prohibit directory listing in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!