【发布时间】:2020-01-30 12:44:23
【问题描述】:
我在index.php 有一个简单的提交表单:
<?php
include('inputs.php');
?>
<form method="post" action= "/index.php">
<input class="button" id="restart_device" name="restart_device" type="submit" value="Restart Display" />
</form>
以及inputs.php 文件中的操作:
if(isset($_POST['restart_device'])) {
shell_exec("sudo /var/www/html/restart_device.sh");
}
问题是每次页面刷新或每次访问页面时都会执行此代码。我不想要这种行为。我只想在按下按钮时执行shell_exec("sudo /var/www/html/restart_device.sh");,而不是在页面访问或页面刷新时执行。
我也尝试过使用<form method="post" action= "">,但没有成功。
【问题讨论】:
-
您在刷新页面时检查了 $_POST['restart_device'] 值吗?因为当不提交表单时,这个参数不会设置值。
-
我不明白你想说什么。这就是涉及输入表单的整个代码。