apache php 验证 登录,在apache服务器中的 PHP 基本验证配置方法

在php中有一种不用写代码也可以进行用户校验,那就是通过.htaccess文件进行控制访问。

例如在根目录下建立下面一个.htaccess 文件就可以控制整个用户的访问。

ErrorDocument 401 /../content.php

AuthUserFile D:/test.htpassword

AuthName 'Realm-Name'

AuthType Basic

require valid-user

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

所谓的基本方式验证,是依赖于浏览器的,火狐浏览器可以不断的让用户输入密码,IE浏览器当用户输错三次之后就跳转到ErrorDocument多定义的链接。

AuthUserFile指定的是用户密码文件,也就是说这个验证是使用文件验证的,不适合于有大量用户群的情况,而且这个文件也不能放在web目录中,因为在web目录中用户

可以直接下载这个文件。

AuthUserFile 通过apache中的htpasswd.exe来生成,运行命令(htpasswd.exe -cbm D:\test.htpassword user1 pass)就可以创建。

同时我们指定验证名称为Realm-Name,类型为Basic。 代码行 require valid-user 表示任何合法的用户都可以访问。

**注释: htpasswd

Usage:

htpasswd [-cmdpsD] passwordfile username

htpasswd -b[cmdpsD] passwordfile username password

htpasswd -n[mdps] username

htpasswd -nb[mdps] username password

-c  Create a new file.

-n  Don't update file; display results on stdout.

-m  Force MD5 encryption of the password (default).

-d  Force CRYPT encryption of the password.

-p  Do not encrypt the password (plaintext).

-s  Force SHA encryption of the password.

-b  Use the password from the command line rather than prompting for it.

-D  Delete the specified user.

On other systems than Windows, NetWare and TPF the '-p' flag will probably not work.The SHA algorithm does not use a salt and is less secure than the MD5 algorithm.

下一篇我们将介绍怎样使用数据库中的用户表进行验证。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值