PHP exec函数来自文本输入

时间:2013-08-20 11:13:01

标签: php html exec

我正在尝试使用php执行一个输入到文本字段的终端命令。 我试图让它使用来自各地的代码。如果你能看到我出错的地方,真的会感激一点......

            <?php
        function doSomething() { 
            echo 'Guess this is working'; 
            exec($command . '2>&1', $output, $return);
            echo "Dir returned $return, and output:\n";
            } 
        if(count($_POST) > 0 && isset($_POST['command'])) \
            { 
            doSomething(); 
            } 
        ?>
        <!DOCTYPE html>

        <html>
        <head>
            <meta content="text/html; charset=utf-8" http-equiv="Content-Type">

            <title>Terminal Emulator</title>
        </head>

        <body>
            <form action="%3C?php%20echo%20$_SERVER['PHP_SELF'];%20?%3E" method="post">
                <input autocomplete="off" id="command" name="command" type="text">
                <input type="submit" value="Submit">
            </form>
        </body>
        </html>

1 个答案:

答案 0 :(得分:0)

<?php
        function doSomething($command) { 
            echo 'Guess this is working'; 
            exec($command . '2>&1', $output, $return);
            echo "Dir returned $return, and output:\n";
            } 
        if(count($_POST) > 0 && isset($_POST['command'])) \
            { 
            doSomething($_POST['command']); 
            } 
        ?>
        <!DOCTYPE html>

        <html>
        <head>
            <meta content="text/html; charset=utf-8" http-equiv="Content-Type">

            <title>Terminal Emulator</title>
        </head>

        <body>
            <form action="%3C?php%20echo%20$_SERVER['PHP_SELF'];%20?%3E" method="post">
                <input autocomplete="off" id="command" name="command" type="text">
                <input type="submit" value="Submit">
            </form>
        </body>
        </html>

//其中是$ output