您的位置:首页 > 运维架构 > Apache

[转贴-半]windows xp下设置apache目录访问身份验证(目录访问控制)方案

2006-09-27 13:28 459 查看

http://www.99power.com/wz_109095/

windows xp下设置apache目录访问身份验证(目录访问控制)方案

一.编辑httpd.conf
加入
Alias /picture/ "E:/picture/"
#设置虚拟目录picture到根目录
<Directory "E:/picture/">
Options Indexes MultiViews
AllowOverride AuthConfig
Order Deny,Allow
Allow from all
Options All
AllowOverride All
</Directory>
二.在E:/picture/下创建.htaccess文件
authtype basic
authname "登陆凡星专区"
authuserfile e:/picture/.htpasswd
require valid-user
三.在E:/picture/下创建密码文件
1.明文密码:
创建pass.txt
内容格式为:username:password
冒号前为用户名,后面为密码,可以放到其他目录,二中的authuserfile的目录也要相应的改动。
2.创建MD5加密的密码文件
在虚拟DOS下进入你的apache目录下的bin目录,输入命令
htpasswd -c e:\picture\.htpasswd fanxing
接下去要求输入两次密码
上面命令行的意思是在E:/picture/下创建密码档.htpasswd
。好了,现在重启apache,在IE里访问picture就要求输入用户名和密码了!
[color=red:21ccfd3b0b]以上部分参考了linux下配置的资料,由谢丹峰@zucc在Windows XP下实践并整理成文,如需转载,请注明出处[/color:21ccfd3b0b]

补充
也可以这样
编辑httpd.conf

<Directory "f:/web/test">
Options Indexes FollowSymlinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
AuthType Basic
AuthName "protected area!"
AuthUserFile f:/web/test/passwd.txt
#require user 123
require valid-user
</Directory>

以下为原创

/article/4793928.html

<?php
require_once("iecho.php");

//header('WWW-Authenticate: Basic realm="验证"');

$user=$_SERVER['PHP_AUTH_USER'];
$pass=$_SERVER['PHP_AUTH_PW'];

if(!$user){
header('WWW-Authenticate: Basic realm="验证"');
Header("HTTP/1.0 401 Unauthorized");
}

echo $user ;
echo $pass ;

prt($_SERVER);
?>

用socket模拟和服务器通信只要在发送的http头里增加一个参数

Authorization: Basic 认证变量

认证变量为base64对id和password的值对编码得到的字串

$user=1;
$pass=1;

$userid_password = base64_encode($user . ":".$pass);
$headAuth ="Authorization: Basic ".$userid_password;

花了我四个小时,NND.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐