Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
让apache在无效的HttDigest(http身份验证)登录上发送php脚本的最佳方法?_Php_Apache_Authentication_Htdigest - Fatal编程技术网

让apache在无效的HttDigest(http身份验证)登录上发送php脚本的最佳方法?

让apache在无效的HttDigest(http身份验证)登录上发送php脚本的最佳方法?,php,apache,authentication,htdigest,Php,Apache,Authentication,Htdigest,因此,我们的源代码库中有几个文件夹是受保护的 我们希望通过自己的定制php处理程序记录无效登录 我希望通过apacheerrordocument指令来实现这一点 所以我想我的问题有两层 a) 将apacheerrordocument指令指向一个php脚本是否有效,它是否会被解析为一个php脚本(假设php已经为上述httpd启动并运行) b) 我快速查看了http状态代码列表 10.4.2未经授权 请求需要用户身份验证。响应必须包括WWW Authenticate标头字段(第14.47节),其

因此,我们的源代码库中有几个文件夹是受保护的

我们希望通过自己的定制php处理程序记录无效登录

我希望通过apacheerrordocument指令来实现这一点

所以我想我的问题有两层

a) 将apacheerrordocument指令指向一个php脚本是否有效,它是否会被解析为一个php脚本(假设php已经为上述httpd启动并运行)

b) 我快速查看了http状态代码列表


10.4.2未经授权

请求需要用户身份验证。响应必须包括WWW Authenticate标头字段(第14.47节),其中包含适用于请求资源的质询。客户可以使用合适的授权标头字段重复请求(第14.8节)。如果请求已包括授权凭据,则401响应表示已拒绝这些凭据的授权。如果401响应包含与先前响应相同的质询,并且用户代理已至少尝试了一次身份验证,则应向用户呈现响应中给出的实体,因为该实体可能包括相关诊断信息。HTTP访问身份验证在“HTTP身份验证:基本和摘要访问身份验证”[43]中进行了解释


这听起来像是基于浏览器的useragent的流程如下所示:

a) user hits protected url
b) apache responds with a 401 status code
c) user is presented by useragent with username + password prompt
<?

if(isset($_SERVER['REDIRECT_REMOTE_USER'])){
    logError('authentication','invalid login attempt to '.(isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']:'unknown').' using username '.$_SERVER['REDIRECT_REMOTE_USER']);
}

header($_SERVER['SERVER_PROTOCOL'].' 401 Authorization Required',true);
header('Status: 401 Authorization Required',true);

?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>401 Authorization Required</title> 
</head><body> 
<h1>Authorization Required</h1> 
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p> 
</body></html>
我们只想记录无效的登录,而不是不知道页面需要身份验证的点击

基本上,我会在这里做一点复制粘贴,但我们需要的是一个定制的、基于php的替代品,用于以下内容:

Authorization Required

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

我们不想做的事情:

a) 被告知,在这种情况下,我们应该使用一个完整的基于php的登录系统。这已经完成,身份验证是两层的。用户必须通过基于web的登录(基于会话)登录到该服务。第二层身份验证是基于http的身份验证

b) 被告知要设置一个完全定制的基于php的http身份验证处理程序。是的,我知道这是可能的,而且相当容易,但我希望将实际的htdigest处理交给apaches。但是,如果将http身份验证处理留在apache手中是不可能的,那么我们将不得不这样做



总而言之:有没有可能让apache基于无效的HttDigest登录解析一个基于php的脚本(但不缺少),这样我们就可以在该脚本中执行操作(日志、ip块等)?

据我们所知,以下方法是有效的。即使基于HttDigest的身份验证即将过期:

a) 将ErrorDocument401指向基于php的脚本

b) 我们的php 401脚本如下所示:

a) user hits protected url
b) apache responds with a 401 status code
c) user is presented by useragent with username + password prompt
<?

if(isset($_SERVER['REDIRECT_REMOTE_USER'])){
    logError('authentication','invalid login attempt to '.(isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']:'unknown').' using username '.$_SERVER['REDIRECT_REMOTE_USER']);
}

header($_SERVER['SERVER_PROTOCOL'].' 401 Authorization Required',true);
header('Status: 401 Authorization Required',true);

?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>401 Authorization Required</title> 
</head><body> 
<h1>Authorization Required</h1> 
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p> 
</body></html>

401需要授权
需要授权
此服务器无法验证您是否
您有权访问该文档
请求。要么你提供的是错误的
凭据(例如,错误的密码)或您的
浏览器不了解如何提供
所需的凭据。

logError函数是我们的一个自定义函数,但是您可以将其替换为任何您喜欢的函数/在其中添加一些进一步的操作


享受吧

据我们所知,以下方法是有效的。即使基于HttDigest的身份验证即将过期:

a) 将ErrorDocument401指向基于php的脚本

b) 我们的php 401脚本如下所示:

a) user hits protected url
b) apache responds with a 401 status code
c) user is presented by useragent with username + password prompt
<?

if(isset($_SERVER['REDIRECT_REMOTE_USER'])){
    logError('authentication','invalid login attempt to '.(isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']:'unknown').' using username '.$_SERVER['REDIRECT_REMOTE_USER']);
}

header($_SERVER['SERVER_PROTOCOL'].' 401 Authorization Required',true);
header('Status: 401 Authorization Required',true);

?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>401 Authorization Required</title> 
</head><body> 
<h1>Authorization Required</h1> 
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p> 
</body></html>

401需要授权
需要授权
此服务器无法验证您是否
您有权访问该文档
请求。要么你提供的是错误的
凭据(例如,错误的密码)或您的
浏览器不了解如何提供
所需的凭据。

logError函数是我们的一个自定义函数,但是您可以将其替换为任何您喜欢的函数/在其中添加一些进一步的操作


享受吧