【问题标题】:Is there a way not allow direct access to cgi-bin but only allow local php access有没有办法不允许直接访问cgi-bin而只允许本地php访问
【发布时间】:2013-11-22 19:13:26
【问题描述】:

现在用户可以通过url直接执行cgi-bin目录下的东西 http:\someserver\cgi-bin\mycommand

我不想让用户这样做,但允许使用下面的代码执行 php 脚本。

这可能吗? 提前致谢

define ("CGI_CMD_URL_URL",          "http://" . $_SERVER['HTTP_HOST'] . "/cgi-bin/mycommand");

// use key 'http' even if you send the request to https://...
$options = array
(
   'http' => array
   (
        'header'  => 'Content-type: application/x-www-form-urlencoded\r\n',
        'method'  => 'POST',
        'content' => $data,
   ),
);

// create context
$context = stream_context_create($options);

// open the stream to get the output from CGI_CMD_URL_URL
$uploadstream = @fopen(CGI_CMD_URL_URL, 'rb', false, $context);
if (!$uploadstream)
{
    $_SESSION[ADDITIONAL_MSG] = $php_errormsg;
    report_error(SOME_ERROR);
}

// read the result
$result = stream_get_contents($uploadstream);

// close the stream
fclose($uploadstream);

// return data
return $result;

【问题讨论】:

    标签: php apache cgi-bin


    【解决方案1】:

    是的,如果是 Apache Webserver,则使用 .htaccess。您必须全部拒绝,只允许您的主机。

    http://httpd.apache.org/docs/2.2/howto/access.html

    请尊重您的网络服务器上的任何自调用方法都是一种尝试,它会影响您的服务器性能并减少该引擎上可能的最大客户端调用。在我看来,这样的任务是最糟糕的做法(在很多情况下)。

    【讨论】:

      猜你喜欢
      • 2013-10-27
      • 1970-01-01
      • 2014-10-05
      • 1970-01-01
      • 1970-01-01
      • 2017-02-05
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多