Home php教程 php手册 我来写个详细的: Win32下具体实现Apache的用户验证(原创)

我来写个详细的: Win32下具体实现Apache的用户验证(原创)

Jun 21, 2016 am 09:12 AM
apache localhost test user users

apache|原创

Win32下具体实现Apache的用户验证
相信大家采用的验证方法很多种,而在Win32环境下如何设置Apache用户验证的介绍很少,手册上介绍的也是Unix和linux环境下的配置,象我这样在win32下苦苦摸索Apache的人应该不少,我根据自己的经验介绍一下自己是如何在Win32环境下实现apache的用户验证功能的。

方法一:以单用户方式实现某目录只能由某个用户或几个用户访问。
假设Apache的web根目录为 d:/home,对应URL为 http://localhost/
如欲使d:/home/test目录只能由某用户访问,该目录对应URL为http://localhost/test,访问该URL时需要弹出验证对话框。
d:/users目录用来存放密码文件 user.passwd

1、制作用户密码文件
在命令行方式先用Apache自带的工具htpasswd.exe生成一个密码文件叫user.passwd,-c参数表示新建文件,无参数表示在该口令文件中以添加方式增加一个用户。
D:\apache\bin>htpasswd -bc d:/users/user.passwd user1 123456
这样,就生成了d:/users/user.passwd 口令文件,里面有一行文字 user1:$apr1$4S3.....$.su.8AIrDEYMX7jKv2RT9/
成功增加了一个user1的用户,如果想再添加其他用户,就采用追加方式添加用户:
D:\apache\bin>htpasswd -b d:/users/user.passwd user2 123456
D:\apache\bin>htpasswd -b d:/users/user.passwd user3 123456

好了,当添加完用户,就可以着手实现用户验证了。

2、制作访问验证文件 .htaccess
打开记事本,输入以下文字:

authtype basic
authname "www.home.net"
authuserfile d:/users/users.passwd
require user user1

然后另存为 .htaccess,保存路径为你想实现验证的目录:d:/home/test/下,注意保存类型选"所有文件",文件名为".htaccess",否则就不会生成 .htaccess 文件了。

到这里,指定某个用户验证的设置就完成了,在浏览器中输入验证目录所对应的地址 http://localhost/test/,会发现浏览器弹出一个对话框要求你输入用户名和口令,你就只能输入用户user1和密码12345才能进去,输入其他用户如user2,user3是没用的。

3、实现指定某几个用户对一个目录的验证
例如决定 http://localhost/test/ 能由user1和user3访问,user2不能访问,则编辑 d:/home/test/.htaccess 文件,把最后的一句:
require user user1
改为:
require user user1 user3
如此就实现了 http://localhost/test/ 只能由user1和user2访问

4、实现所有合法用户对一个目录的验证
例如决定 http://localhost/test/ 能由 d:/users/user.passwd 文件里的所有用户访问,则编辑 d:/home/test/.htaccess 文件,把最后的一句改为 :

require valid-user

就可以实现在 user.passwd 里用户都能访问http://localhost/test/了,只要输入的用户名和密码没有错误。

方法二:采用群组用户方式实现验证
要实现其实也很简单,在方法一中对 user.passwd 文件里的用户进行分组,建立用户组文件,再在 .htaccess 文件里指定 authgroupfile 就可以了。假设 user.passwd 中已经添加了很多用户 (user1,user2,user3,user4,...)
1、建立一个用户组文件 d:/users/user.group ,内容如下:

manager:user1 user3
game:user2 user4
download:user5 user6 user7

如此,user.group 文件里把 user1至user7这7个用户分为了3个组:manager,game,download 。

2、实现某组用户能访问 http://localhost/test/
编辑 d:/home/test/.htaccess 文件,内容如下:

authtype basic
authname "www.home.net"
authuserfile d:/users/users.passwd
authgroupfile d:/users/user.group
require group game

那么,http://localhost/test/就只能由 game组里的用户 user2,user4 才能访问了。

以上步骤,对于熟悉编程开发的同志来说,完全可以做个图形界面程序来完成,就省事多了。
至此,Apache在Win32环境下的简单验证就实现了。看来和 Linux下的设置方法差不多,我却走了不少弯路才摸索出来,惭愧惭愧啊。
实现Apache的验证方法还有数种途径,以上只是一方面而已。



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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Huawei Watch GT 5 smartwatch gets update with new features Huawei Watch GT 5 smartwatch gets update with new features Oct 03, 2024 am 06:25 AM

Huawei is rolling out software version 5.0.0.100(C00M01) for the Watch GT 5 and the Watch GT 5 Prosmartwatchesglobally. These two smartwatches recently launched in Europe, with the standard model arriving as the company’s cheapest model. This Harmony

Tekken\'s Colonel Sanders dream fried by KFC Tekken\'s Colonel Sanders dream fried by KFC Oct 02, 2024 am 06:07 AM

Katsuhiro Harada, the Tekken series director, once seriously tried to bring Colonel Sanders into the iconic fighting game. In an interview with TheGamer, Harada revealed that he pitched the idea to KFC Japan, hoping to add the fast-food legend as a g

New Xiaomi Mijia Graphene Oil Heater with HyperOS arrives New Xiaomi Mijia Graphene Oil Heater with HyperOS arrives Oct 02, 2024 pm 09:02 PM

Xiaomi will shortly launch the Mijia Graphene Oil Heater in China. The company recently ran a successful crowdfunding campaign for the smart home product, hosted on its Youpin platform. According to the page, the device has already started to ship to

How to efficiently integrate Node.js or Python services under LAMP architecture? How to efficiently integrate Node.js or Python services under LAMP architecture? Apr 01, 2025 pm 02:48 PM

Many website developers face the problem of integrating Node.js or Python services under the LAMP architecture: the existing LAMP (Linux Apache MySQL PHP) architecture website needs...

How to run the h5 project How to run the h5 project Apr 06, 2025 pm 12:21 PM

Running the H5 project requires the following steps: installing necessary tools such as web server, Node.js, development tools, etc. Build a development environment, create project folders, initialize projects, and write code. Start the development server and run the command using the command line. Preview the project in your browser and enter the development server URL. Publish projects, optimize code, deploy projects, and set up web server configuration.

How does Apache or Nginx work together with PHP: What is the difference between mod_php5, php-cgi and php-fpm? How does Apache or Nginx work together with PHP: What is the difference between mod_php5, php-cgi and php-fpm? Apr 01, 2025 pm 12:15 PM

The collaborative working mechanism between Apache or Nginx and PHP: Comparison of mod_php5, php-cgi and php-fpm is to use Apache or Nginx to build a web server and use PHP for backend...

How is Debian Hadoop compatibility How is Debian Hadoop compatibility Apr 02, 2025 am 08:42 AM

DebianLinux is known for its stability and security and is widely used in server, development and desktop environments. While there is currently a lack of official instructions on direct compatibility with Debian and Hadoop, this article will guide you on how to deploy Hadoop on your Debian system. Debian system requirements: Before starting Hadoop configuration, please make sure that your Debian system meets the minimum operating requirements of Hadoop, which includes installing the necessary Java Runtime Environment (JRE) and Hadoop packages. Hadoop deployment steps: Download and unzip Hadoop: Download the Hadoop version you need from the official ApacheHadoop website and solve it

Apache Troubleshooting: Diagnosing & Resolving Common Errors Apache Troubleshooting: Diagnosing & Resolving Common Errors Apr 03, 2025 am 12:07 AM

Apache errors can be diagnosed and resolved by viewing log files. 1) View the error.log file, 2) Use the grep command to filter errors in specific domain names, 3) Clean the log files regularly and optimize the configuration, 4) Use monitoring tools to monitor and alert in real time. Through these steps, Apache errors can be effectively diagnosed and resolved.

See all articles