【发布时间】:2014-01-09 18:35:58
【问题描述】:
我正在寻找一个有效的 php 脚本,它可以记录/保存尝试的用户名和密码组合,以访问我受保护的 .htpasswd 文件(.htaccess 文件将人们重定向到这个 php 脚本文件)。我找到了这个:
<?php
define('LOGINS_LOG','/web/user/log-htpasswd.log');
if(isset($_ENV['REDIRECT_REMOTE_USER']) && !empty($_ENV['REDIRECT_REMOTE_USER'])){
$fp = fopen(LOGINS_LOG, 'a+');
fwrite($fp, $_ENV['REDIRECT_REMOTE_USER']);
fclose($fp);
}
ob_start();
header("HTTP/1.1 401 Authorization Required",1);
header("Status: 401 Authorization Required",1);
echo '<!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>';
exit;
exit();
?>
但是当我尝试使用它时,我收到以下错误消息:
解析错误:语法错误,意外的 T_STRING,需要 ',' 或 ';'在 /web/user/log-htpasswd.log 第 20 行
有人知道一个可以运行的php脚本吗?
【问题讨论】:
-
当你写“doesn't”时你打破了你的回声,因为它包含一个'
-
正确转义引号。
-
尝试像这样反斜杠引号:does\'t
-
这是真正的错误信息:
... in /web/user/log-htpasswd.log?似乎不太可能。