Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.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
什么PHP脚本将执行此功能:_Php_Html_.htaccess - Fatal编程技术网

什么PHP脚本将执行此功能:

什么PHP脚本将执行此功能:,php,html,.htaccess,Php,Html,.htaccess,我正在寻找一个可以工作的php脚本,该脚本将记录/保存尝试的用户名和密码组合,以访问我的受保护的.htpasswd文件(该.htaccess文件正在将用户重定向到此php脚本文件)。我发现了这个: <?php define('LOGINS_LOG','/web/user/log-htpasswd.log'); if(isset($_ENV['REDIRECT_REMOTE_USER']) && !empty($_ENV['REDIRECT_REMOTE_USER'])){

我正在寻找一个可以工作的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();
?>

检查第19行的问号,您需要避开它们:

browser doesn\'t understand how to supply
转义
“不”


执行以下操作

$content = date('m-d-Y g:i:sa')." | ".$_SERVER['REMOTE_ADDR']." has visited
";
$fp = fopen("C:\\logs\\accesslog.txt","a");
fwrite($fp,$content);
fclose($fp);

您有两个选项

错误:下面的代码体导致了一个分析错误,这是由于单词
not

  • 选项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>';
  • 选项2:
根据以下内容将
更改为


这也是一个解决方案,如果不是最好的话。

当你写“不”时,你会打断你的回音,因为它包含一个“正确的转义引号”。试着像这样反斜杠引号:不可能重复的是真正的错误信息:
。。。在/web/user/log htpasswd.log中
?似乎不太可能。此脚本只会导致accesslog.txt显示:12-20-2013 2:56:28pm | IP地址已访问。我如何让它告诉用户/pass输入访问权限?当然,您必须编辑$content变量,使其等于您希望它记录的任何信息。不幸的是,我真的是个新手…那么脚本到底会是什么样子?我试图以我认为有效的方式梳理这两个脚本,但却出现了错误。提前谢谢。
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>';
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>";