Adding user authentication functions in Apache

xiaoxiao2021-03-06  86

1. Must ensure that there is no ALLOWOVERRIDE NONE to this file area (which can be set to ALL)

Then use the .htacess method to realize the authentication function:

Add a .htacess file in the area you want to set the authentication, the contents of the file are as follows:

ErrorDocument 401 / Error.php // URL

Authorfile d: /websamples/phpmysql/chapter14/protected/.htpass // Physical path

Authname "Realm-Name"

Authtype Basic

Require Valid-User

Where. Htpass files are used to use an HTPasswd.exe tool under Apache / bin generation:

HTPASSWD -BC path /.htpass user1 pass1

HTPASSWD -B path /.htpass user2 pass2

The above command generates a .htpass file in the specified path, which contains the user and the corresponding password.

2, modify the http.conf configuration file directly

Options Followsymlinks

ALLOWOVERRIDE ALL

ErrorDocument 401 / Error.php

Authorfile d: /websamples/phpmysql/chapter14/protacected/.htpass

Authname "Realm-Name"

Authtype Basic

Require Valid-User

转载请注明原文地址:https://www.9cbs.com/read-122033.html

New Post(0)