命令行-如何使用exec() PHP发送变量


command line - How to send variables using exec() PHP

我试图将php变量发送到函数,但以下都没有传递变量。

$vars='email=' . $_POST['email'] . '&password=' . $_POST['password'] . '&server=' . $_POST['server'];
$function = 'nohup php unsubscribefunction.php ' . escapeshellarg($vars);
exec($function); 
exec('nohup php unsubscribefunction.php ' . $vars);
exec('nohup php unsubscribefunction.php $vars ');

$vars='?email=' . $_POST['email'] . '&password=' . $_POST['password'] . '&server=' . $_POST['server'];
$function = 'nohup php unsubscribefunction.php' . $vars;
exec($function); 

以下是php.net页面对

的说明

允许用户提供的数据传递给这个函数,使用escapeshelllang()或escapeshellmd ()以确保用户不能欺骗系统执行任意命令。

但是,没有关于如何传递变量的示例,任何见解或示例都将受到赞赏。

尝试阅读这里的一些帮助。基本上,您需要确保通过$argc/getopt()或其他方式使用命令行变量。

用标志调用脚本,如:php myscript.php -a foo -b bar -c baz测试打印参数:

   <?php
           $arguments = getopt("a:b:c:");
           print_r($arguments);
    ?>
Array
(
    [a] => foo
    [b] => bar
    [c] => baz
)

这不是你遇到的问题。你不能这样发送变量;您需要使用命令行参数来捕获您想要放入变量中的值。