【问题标题】:PHP System call with JS variable带有 JS 变量的 PHP 系统调用
【发布时间】:2016-07-27 16:27:30
【问题描述】:

这是我的 Javascript:

var url = "load.php?x="+x;
xmlhttp.open("GET", url, true);

其中 x 是一个已定义的变量。

这是我的 PHP:

$var = $_GET['x'];
echo shell_exec('./test2/test2 $var');

其中 test2 是一个包含可执行文件的文件夹,而 $var 是一个参数。这适用于我的第二个语句是

echo shell_exec('./test2/test2 param');

这显示在我的错误日志中:

terminate called after throwing an instance of 'terminate called after throwing an instance of 'std::logic_errorstd::logic_error'
 what():    what():  basic_string::_S_construct NULL not validbasic_string::_S_construct NULL not valid
terminate called after throwing an instance of 'std::logic_error'
what():  basic_string::_S_construct NULL not valid

我做错了什么?

谢谢!

【问题讨论】:

  • 您使用的是单引号...尝试更改为'./test2/test2' . $var"./test2/test2 $var"

标签: javascript php parameters xmlhttprequest system-calls


【解决方案1】:

我认为您的问题是因为您试图在使用单引号定义的字符串中插入一个变量。请改用双引号。相关引用来自manual

注意:与双引号和heredoc语法不同,特殊字符的变量和转义序列在出现在单引号字符串中时不会被扩展。

echo shell_exec("./test2/test2 $var");

【讨论】:

  • 已同步.. 2s diff xD(来自我的评论)
  • 哈哈是的,我刚发帖就看到了你的评论。如果这是正确的,那么伟大的思想就会有相似之处。否则,我们会羞愧地低下头。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-07-25
  • 2023-04-10
  • 2015-02-06
  • 2012-04-07
  • 2018-07-08
  • 2012-07-27
  • 1970-01-01
相关资源
最近更新 更多