A button to start php script, how? A button to start php script, how? php php

A button to start php script, how?


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

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


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.

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.

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:

<?phpecho '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.


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

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

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