【发布时间】: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;
【问题讨论】: