2013-11-22 203 views
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; 

回答

1

是,在Apache服務器的情況下的.htaccess。你必須全部否認,只允許你的主機。

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

尊重您的網絡服務器任何自我調用的方法是一個嘗試,影響你的服務器性能並減少可能的最大客戶端調用該引擎。在我看來,這些任務是最糟糕的做法(在很多情況下)。

相關問題