0
現在用戶可以通過使用url直接執行cgi-bin目錄中的某些東西http:\ someserver \ cgi-bin \ mycommand有沒有辦法允許直接訪問cgi-bin,但只允許本地php訪問
我不想讓用戶這樣做,但允許使用下面的代碼執行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;