2013-07-17 189 views
0

我正在通過PHP exec()函數執行php函數,但它似乎只在時間通過1個變量。Shell命令不能通過exec()在php

$url = "http://domain.co/test.php?phone=123&msg=testing" 
exec('wget '.$url); 

在test.php的文件,我有

$msg = "msg =".$_GET["msg"]." number=".$_GET["phone"]; 
mail('[email protected]', 'Working?', $msg); 

我得到的只有返回電話可變的電子郵件。

但如果我更改網址如下

$url = "http://domain.co/test.php?msg=testing&phone=123" 

我得到msg但不phone?任何想法是什麼導致這種奇怪的行爲?

回答

4

&符號是Unix shell中的一個特殊字符。你需要逃避它:

exec("wget '$url'"); 

另外,如果您的網址是基於以任何方式的用戶輸入,非常小心escapeshellarg逃脫它。否則你的用戶將能夠在你的服務器上運行任意的Unix命令。

1
$url = "http://domain.co/test.php?phone=123&msg=testing" 
exec('wget "'.$url.'"'); 

需要qoute網址


&是符號用於把一個任務分解成背景