首页 > 解决方案 > 使用 PHP exec 执行 Minecraft 命令

问题描述

我正在创建自己的小网站来管理 Minecraft 服务器作为有趣的项目。现在我需要完成的是能够将命令发送到服务器正在运行的屏幕。

我的方法如下:

<?php
if (isset($_POST['startbutton']))
    {
        exec('sudo screen -S 23971 -X stuff "say hello^M"');
    }
?>

    
<form method="post">
    <button type="submit" name="startbutton">Test</button>
</form>

现在,当我在终端本身中执行该命令行时,它工作得很好,但是当我尝试在网站上运行它时,什么也没有发生。如果我只是尝试执行

if (isset($_POST['startbutton']))
    {
        echo exec('whoami');
    }
?>

它也可以正常工作。我不知道我做错了什么。

标签: phpexecminecraft

解决方案


我真的不确定,但试试:

<?php
if (isset($_POST['startbutton']))
    {
        exec('sudo screen -S 23971 -X stuff "say hello^M"');
        exec('YOUR SUDO PSW');
    }
?>


<form method="post" action="YOUR PHP PAGE LIKE server.php">
    <button type="submit" name="startbutton">Test</button>
</form>

让我知道它是否有效


推荐阅读