一键启动php脚本,如何? [英] A button to start php script, how?
问题描述
我想创建一个按钮,单击它后将启动我的php脚本.那么,我是否只制作2个单独的文件并将动作发布到php文件中,然后让它启动?还是有更好的方法来做到这一点?可能在一个文档中?
I want to make a button that starts my php script after I click it. So do I just make 2 separate files and have action post to the php file and then let it start? or is there a better way to do this? Possibly in one document?
更新:
好吧,我基本上制作了一个脚本,该脚本将执行一系列循环,直到完成为止.因此,通常当我访问该页面时,它会自动启动,因此我仅在需要时创建一个按钮来启动它.
Well, I basically made a script that would do a series of a loops until it's finished. So usually when I visit the page it automatically starts, so I'm making a button to start it only when I need it.
更多信息:回答其中一个问题,启动脚本"只能执行脚本.
More info: Answer to one of the questions, "starting the script" as in it would only execute the script.
更多信息:我真的不需要将任何数据从提交表单传递到php脚本.我只希望我的脚本在按下按钮时运行.我只想知道什么是最好的方法.
More info: I really don't need to pass any data from the submit form to the php script. I just want my script to run when I hit a button. I just want to know what's the best way to do this.
推荐答案
拥有2个像您建议的文件将是最简单的解决方案.
Having 2 files like you suggested would be the easiest solution.
例如:
(.. your html ..)
<form action="script.php" method="get">
<input type="submit" value="Run me now!">
</form>
(...)
script.php
<?php
echo "Hello world!"; // Your code here
?>
单个文件解决方案:
index.php
<?php
if (!empty($_GET['act'])) {
echo "Hello world!"; //Your code here
} else {
?>
(.. your html ..)
<form action="index.php" method="get">
<input type="hidden" name="act" value="run">
<input type="submit" value="Run me now!">
</form>
<?php
}
?>
这篇关于一键启动php脚本,如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!