我试图将 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);
这就是 the php.net page说的是这个
When allowing user-supplied data to be passed to this function, use escapeshellarg() or escapeshellcmd() to ensure that users cannot trick the system into executing arbitrary commands.
但是,没有关于如何传递变量的示例,任何见解或示例将不胜感激。
最佳答案
尝试阅读一些帮助 here 。基本上,您需要确保通过 $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
)
关于php - 如何使用 exec() PHP 发送变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5797199/