dongruo0909 2013-12-20 20:24
浏览 61
已采纳

什么PHP脚本将执行此功能:[关闭]

I'm looking for a working php script that will work to log/save attempted username and password combinations to access my protected .htpasswd file (the .htaccess file is redirecting people to this php scripted file). I found this one:

<?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();
?>

But when i attempt to use it i get this error message:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /web/user/log-htpasswd.log on line 20

Anyone know a php script that will work?

  • 写回答

4条回答 默认 最新

  • drr7731 2013-12-20 20:31
    关注

    You have 2 options

    Fault: Your body of code below, caused a parse error and this is due to an unescaped quote in the word doesn't

    • Option 1:

    Change this body of text/code:

    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>';
    

    to this: (while escaping the quotes "-//IETF//DTD HTML 2.0//EN") with \"

    and using double quotes for your echo.

    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>";
    
    • Option 2:

    Change doesn't to doesn\'t as per:

    Eduardo Stuart's answer which is also a solution, if not the best actually.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件