代碼如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>MAC search</title>
</head>
<body align="middle" bgcolor="gray">
<h1><font size="20" face="Verdana" color="blue">MAC search</font></h1>
<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.問題解決