php - 如何修复未使用表单输入执行的 php 代码?
问题描述
我是新来的 php。
我正在运行一个简单的 php 代码来 ssh 到远程服务器并执行一个长命令:
ldapsearch -b o=Devices -h 24.33.42.43 -D "uid=aaa_user,ou=AppUsers,o=services" -w "authAuthAcc01" rrWiFiDeviceMAC="A4-F1-E8-24-6B-28"
对于特定的 MAC 地址A4-F1-E8-24-6B-28。我用一个表格输入一个MAC地址,然后提交执行ssh到linux服务器,再执行上面的命令。echo $CMD
将在指示$var=$_POST[]
作品的页面上显示完整的命令。但是,代码不会运行到 ssh2 函数。这就像$var
变得空虚或什么的。但是,如果我硬编码$var
并从 PHP 命令行运行,它就可以工作。请问,我做错了什么!
谢谢你的帮助。
<form action="MAC_search.php" method="post">
Enter MAC Address to Search:<input type="text" name="mac">
<input type="submit" name='submit' value ='Search' />
</form>
<?php
if ($_POST["submit"] ){
$MACD=$_POST['mac'];
//$MACD='F8-62-14-E9-F7-51'; *****Hardcoding here works*****
$CMD = "ldapsearch -b o=Devices -h 24.33.33.5 -D \"uid=a .
aa_user,ou=AppUsers,o=services\" -w \"authAuthAcc01\"
rrWiFiDeviceMAC=\"$MACD\"";
echo $CMD; **** Here echos on the page also *******
$connection = ssh2_connect("x.x.x.x", 22);
ssh2_auth_password($connection, $username, $password);
$stream = ssh2_exec($connection, "$CMD");
stream_set_blocking($stream, true);
$output = stream_get_contents($stream);
$resultfile = fopen("data.txt", "w") or die("unable to open
file");
fwrite($resultfile, $output);
fclose($myfile);
}
?>
解决方案
推荐阅读
- c - 使用 sscanf 解析单行的长行单词
- mysql - 如何添加日期格式以将 Excel 日期转换为 MySQL 中的普通日期?
- python - 输入没有从函数返回?
- express - RStudio 代理身份验证
- git - 从不同的邮件地址将 git 项目导入 gitlab 帐户
- java - java.lang.NoClassDefFoundError: org/nd4j/linalg/api/ops/impl/transforms/floating/Histogram
- sqlite - 如何将 dotnetcore/react -au Individual 部署到 Azure
- visual-studio - 卸载 Visual Studio 2017“解析值时遇到意外字符”
- javascript - 如何将现有标签列表添加到 Gutenberg WordPress 中标签面板的描述中
- android - 使用 Kotlin 从 Firebase 检索 HashMap