[英]How to execute sh file by PHP from web page
echo 'test';
<?php
echo 'start'.PHP_EOL;
echo shell_exec('/bin/sh /root/script/test.sh');
echo 'end'.PHP_EOL
如果我在本地php sh.php
运行PHP,则start test end
,但是如果我从url http://example.com/sh.php
运行php,则只能start end
,则脚本不会执行,但是如果我执行echo shell_exec('ls -al');
,它将显示网页上的列表。
使用file_get_contents
尝试一下:
$path = file_get_contents('/root/script/test.sh');
echo shell_exec($path);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.