一个启动php脚本的按钮,怎么样?

时间:2022-03-27 01:11:59

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?

我想点击它后创建一个启动我的PHP脚本的按钮。所以,我只是制作2个单独的文件,并将动作发布到php文件,然后让它启动?或者有更好的方法吗?可能在一个文件中?

Update:

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.

更多信息:回答其中一个问题,“启动脚本”就像执行脚本一样。

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.

更多信息:我真的不需要将提交表单中的任何数据传递给php脚本。我只想在按下按钮时运行脚本。我只想知道最好的方法是什么。

5 个解决方案

#1


18  

Having 2 files like you suggested would be the easiest solution.

拥有像您建议的2个文件将是最简单的解决方案。

For instance:

2 files solution:

index.html

(.. 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
?>

Single file solution:

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
  }
?>

#2


1  

You could do it in one document if you had a conditional based on params sent over. Eg:

如果您根据发送的params有条件,则可以在一个文档中执行此操作。例如:

if (isset($_GET['secret_param'])) {
    <run script>
} else {
    <display button>
}

I think the best way though is to have two files.

我认为最好的方法是拥有两个文件。

#3


1  

I know this question is 5 years old, but for anybody wondering how to do this without re-rendering the main page. This solution uses the dart editor/scripting language.

我知道这个问题已经有5年了,但对于任何想知道如何在不重新渲染主页的情况下做到这一点的人来说。此解决方案使用dart编辑器/脚本语言。

You could have an <object> tag that contains a data attribute. Make the <object> 1px by 1px and then use something like dart to dynamically change the <object>'s data attribute which re-renders the data in the 1px by 1px object.

您可以拥有一个包含数据属性的标记。使 1px乘以1px,然后使用类似dart的东西动态更改的数据属性,该属性重新呈现1px xpx对象中的数据。

HTML Script:

<object id="external_source" type="text/html" data="" width="1px" height="1px">
</object>

<button id="button1" type="button">Start Script</button>

<script async type="application/dart" src="dartScript.dart"></script>
<script async src="packages/browser/dart.js"></script>

someScript.php:

<?php
echo 'hello world';
?>

dartScript.dart:

import 'dart:html';

InputElement button1;
ObjectElement externalSource;

void main() {
    button1 = querySelector('#button1')
        ..onClick.listen(runExternalSource);

    externalSource = querySelector('#external_source');
}

void runExternalSource(Event e) {
    externalSource.setAttribute('data', 'someScript.php');
}

So long as you aren't posting any information and you are just looking to run a script, this should work just fine.

只要你没有发布任何信息而你只是想运行一个脚本,这应该可以正常工作。

Just build the dart script using "pub Build(generate JS)" and then upload the package onto your server.

只需使用“pub Build(生成JS)”构建dart脚本,然后将包上传到您的服务器上。

#4


0  

What exactly do you mean by "starts my php script"? What kind of PHP script? One to generate an HTML response for an end-user, or one that simply performs some kind of data processing task? If you are familiar with using the tag and how it interacts with PHP, then you should only need to POST to your target PHP script using an button of type "submit". If you are not familiar with forms, take a look here.

究竟是什么意思“启动我的PHP脚本”?什么样的PHP脚本?一个是为最终用户生成HTML响应,还是只是执行某种数据处理任务的HTML响应?如果您熟悉使用标记及其与PHP的交互方式,那么您只需要使用“submit”类型的按钮POST到目标PHP脚本。如果您不熟悉表格,请查看此处。

#5


0  

This one works for me:

这个对我有用:

index.php

    <?php
       if(isset($_GET['action']))
              {
                 //your code
                 echo 'Welcome';
              }
    ?>


    <form id="frm" method="post"  action="?action" >
    <input type="submit" value="Submit" id="submit" />
    </form>

This link can be helpful:

此链接可能会有所帮助:

https://blogs.msdn.microsoft.com/brian_swan/2010/02/08/getting-started-with-the-sql-server-driver-for-php/

#1


18  

Having 2 files like you suggested would be the easiest solution.

拥有像您建议的2个文件将是最简单的解决方案。

For instance:

2 files solution:

index.html

(.. 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
?>

Single file solution:

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
  }
?>

#2


1  

You could do it in one document if you had a conditional based on params sent over. Eg:

如果您根据发送的params有条件,则可以在一个文档中执行此操作。例如:

if (isset($_GET['secret_param'])) {
    <run script>
} else {
    <display button>
}

I think the best way though is to have two files.

我认为最好的方法是拥有两个文件。

#3


1  

I know this question is 5 years old, but for anybody wondering how to do this without re-rendering the main page. This solution uses the dart editor/scripting language.

我知道这个问题已经有5年了,但对于任何想知道如何在不重新渲染主页的情况下做到这一点的人来说。此解决方案使用dart编辑器/脚本语言。

You could have an <object> tag that contains a data attribute. Make the <object> 1px by 1px and then use something like dart to dynamically change the <object>'s data attribute which re-renders the data in the 1px by 1px object.

您可以拥有一个包含数据属性的标记。使 1px乘以1px,然后使用类似dart的东西动态更改的数据属性,该属性重新呈现1px xpx对象中的数据。

HTML Script:

<object id="external_source" type="text/html" data="" width="1px" height="1px">
</object>

<button id="button1" type="button">Start Script</button>

<script async type="application/dart" src="dartScript.dart"></script>
<script async src="packages/browser/dart.js"></script>

someScript.php:

<?php
echo 'hello world';
?>

dartScript.dart:

import 'dart:html';

InputElement button1;
ObjectElement externalSource;

void main() {
    button1 = querySelector('#button1')
        ..onClick.listen(runExternalSource);

    externalSource = querySelector('#external_source');
}

void runExternalSource(Event e) {
    externalSource.setAttribute('data', 'someScript.php');
}

So long as you aren't posting any information and you are just looking to run a script, this should work just fine.

只要你没有发布任何信息而你只是想运行一个脚本,这应该可以正常工作。

Just build the dart script using "pub Build(generate JS)" and then upload the package onto your server.

只需使用“pub Build(生成JS)”构建dart脚本,然后将包上传到您的服务器上。

#4


0  

What exactly do you mean by "starts my php script"? What kind of PHP script? One to generate an HTML response for an end-user, or one that simply performs some kind of data processing task? If you are familiar with using the tag and how it interacts with PHP, then you should only need to POST to your target PHP script using an button of type "submit". If you are not familiar with forms, take a look here.

究竟是什么意思“启动我的PHP脚本”?什么样的PHP脚本?一个是为最终用户生成HTML响应,还是只是执行某种数据处理任务的HTML响应?如果您熟悉使用标记及其与PHP的交互方式,那么您只需要使用“submit”类型的按钮POST到目标PHP脚本。如果您不熟悉表格,请查看此处。

#5


0  

This one works for me:

这个对我有用:

index.php

    <?php
       if(isset($_GET['action']))
              {
                 //your code
                 echo 'Welcome';
              }
    ?>


    <form id="frm" method="post"  action="?action" >
    <input type="submit" value="Submit" id="submit" />
    </form>

This link can be helpful:

此链接可能会有所帮助:

https://blogs.msdn.microsoft.com/brian_swan/2010/02/08/getting-started-with-the-sql-server-driver-for-php/