温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

php页面传参给shell脚本

发布时间:2020-07-25 12:48:46 来源:网络 阅读:3843 作者:290480358 栏目:web开发

代码如下:

<html>

<head>

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

<title>MAC search</title>

</head>

<body align="middle" bgcolor="gray">

<h2><font size="20" face="Verdana" color="blue">MAC search</font></h2>

<form action="" method="post">

MAC:

<input type="text" name="mac" size="20"/>

<input type="submit" value="submit"/>

</form>

<?php

if(isset($_POST['mac'])&&$_POST['mac']!=''){

        $mac=$_POST['mac'];

$output = shell_exec("macsearch $mac");

echo "$output";

}

?>

</body>

</html>

分析如下:

    1.通过表单传入一个参数“mac”        

        <form action="" method="post">

        MAC:

        <input type="text" name="mac" size="20"/>

        <input type="submit" value="submit"/>

        </form>

    2.通过php传入参数并且运行shell脚本     

        <?php

        if(isset($_POST['mac'])&&$_POST['mac']!=''){

                $mac=$_POST['mac'];

        $output = shell_exec("macsearch $mac");

        echo "$output";

        }

        ?>


补充:今天遇到一个问题,通过php页面执行这个脚本的时候无效,macsearch脚本中的wget命令未执行(macsearch脚本在博文《字符串按位数分隔》中有)

    1.切换到一个普通用户执行macsearch发现也不执行wget命令

    2.检查目录权限,发现/srv/macsearch/record权限为755,普通用户无写入权限,所以执行:

        chmod -R 777 /srv/macsearch/record

    3.问题解决


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI