2013-07-17 142 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网址


&是符号用于把一个任务分解成背景