Shell_exec 不使用 POST 变量
Shell_exec not working with POST variables
我正在尝试使用 PHP 的 shell_exec
函数将 POST 变量的值发送到 Python 2.7。当我尝试使用预定义变量时,它给出了正确的结果,而当我使用 POST 变量时,它不会将参数发送到 python 文件。 python 脚本也没有执行。
I am using AJAX method to call this file
//Does not work in this case
$age = (int)$_POST['age'];
$gander = $_POST['gander'];
$occupation = $_POST['occupation'];
$n = 5;
//Works when used like this
$age=25;
$gander='M';
$occupation='engineer';
$n=5;
//For result displaying
$res = shell_exec("py -2 main.py $age $gander $occupation $n ");
echo $res;
两个变量几乎相似。当您使用 ajax 方法时,您的 post 值可能具有不同的格式或长度,因此您可以使用 var_dump($var)
来检查并更正两组之间的差异变量。
我正在尝试使用 PHP 的 shell_exec
函数将 POST 变量的值发送到 Python 2.7。当我尝试使用预定义变量时,它给出了正确的结果,而当我使用 POST 变量时,它不会将参数发送到 python 文件。 python 脚本也没有执行。
I am using AJAX method to call this file
//Does not work in this case
$age = (int)$_POST['age'];
$gander = $_POST['gander'];
$occupation = $_POST['occupation'];
$n = 5;
//Works when used like this
$age=25;
$gander='M';
$occupation='engineer';
$n=5;
//For result displaying
$res = shell_exec("py -2 main.py $age $gander $occupation $n ");
echo $res;
两个变量几乎相似。当您使用 ajax 方法时,您的 post 值可能具有不同的格式或长度,因此您可以使用 var_dump($var)
来检查并更正两组之间的差异变量。