正如你它工作在終端上,而不是在apache
那麼Apache的php.ini
文件可能會被禁止使用的shell_exec()
。
見http://www.php.net/manual/en/ini.core.php#ini.disable-functions
你的Apache的php.ini
文件可能看起來像
disable_functions=exec,passthru,shell_exec,system,proc_open,popen
從該列表中刪除shell_exec
並重新啓動Web服務器,雖然這是一個安全風險,我不建議這樣做。
在一般功能如exec
,shell_exec
和system
總是用來執行外部程序。即使是一個shell命令也可以被執行。如果啓用了這兩個功能,那麼用戶可以輸入任何命令作爲輸入並執行到您的服務器中。所以通常人們在Apache配置中禁用爲disable_functions
來保護他們的網站。
它爲我的作品 - 這是試運行
抽樣檢測c
代碼
[[email protected] tmp]$ cat test.c
#include<stdio.h>
int main(int args, char *argv[]) {
int i = 0;
for (i = 0; i < args; i++)
printf("Arg[%d] = %s\n",i, argv[i]);
return 0;
}
編譯
[[email protected] tmp]$ gcc test.c
樣品php
腳本
[[email protected] tmp]$ cat test.php
<?php
$query = "/tmp/./a.out /var/www/project/constraints.txt /var/www/project/constraints_keyword.txt /var/www/project/FIB.txt /var/www/project/ANS.txt";
$var = shell_exec($query);
echo $var;
?>
執行和輸出
[[email protected] tmp]$ php test.php
Arg[0] = /tmp/./a.out
Arg[1] = /var/www/project/constraints.txt
Arg[2] = /var/www/project/constraints_keyword.txt
Arg[3] = /var/www/project/FIB.txt
Arg[4] = /var/www/project/ANS.txt
歡迎堆棧溢出!你可以先參加[遊覽]並學習[問]一個很好的問題,然後創建一個[mcve]。這使我們更容易幫助你。 – Katie
Atleast向我們展示了迄今爲止你做了什麼? –
嘗試引用參數:http://stackoverflow.com/a/16932201/454827 – ZiTAL