简体   繁体   English

php shell_exec返回值到javascript变量不起作用

[英]php shell_exec return value to javascript variable not working

I want to get the output string from php_exec function to a javascript variable. 我想将输出字符串从php_exec函数获取到javascript变量。 But it doesn't work. 但这是行不通的。

<?php
$val1 = "val1 ok";
$val2 = shell_exec('ls');
?>
<html>
<body>
<script>
document.write("<?php echo $val2 ?>"); // val1 works but not val2
</script>
</body>
</html>

I can see val1 get printed but not val2. 我可以看到val1被打印,但是val2没有。 why ? 为什么呢?

According to the PHP documentation , 根据PHP文档

The output from the executed command or NULL if an error occurred or the command produces no output. 执行命令的输出,如果发生错误或命令不产生任何输出,则为NULL

and the shell_exec function "is disabled when PHP is running in safe mode ." 并且shell_exec函数“当PHP以安全模式运行时被禁用。”

$val2 is not displayed because its value is null . 由于$val2的值为null因此不会显示。

Code: 码:

<?php
$val1 = "val1 ok";
$val2 = shell_exec('ls');
?>
<html>
<body>
<script>
document.write("<?php echo 'val2 is '.$val2 ?>"); // val1 works but not val2
</script>
</body>
</html>

Output: 输出:

val2 is

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM