Page 1 of 1

Execute scipt via Html button using php

Posted: Wed Jun 13, 2018 3:10 pm
by yash1947
Hi all,
I am trying to execute a shell script via php and I want to do that using a button i.e. html button. If you click that button, then it should execute that script. In short I need to refresh the page contents by hitting a button present on that page.

I have written the code, but that is not working. As soon as I load the php page (abc.php), it starts executing the script in loop and never stops.

Below is the code :
<?php
if(['button1']) {fun1();}
function fun1() { shell_exec("sh /home/test.sh");
header('Location: http://1.2.3.4/abc.php?success=true');
}
?>

<html>
<body>
<center><button id=btnfun1 name=btnfun1 onClick='location.href=?button1=1'>Refresh</button> <a href=http://1.2.3.4/abc1.html >
<button>HOME</button></a> <a href=http://1.2.3.4/abc2.html >
<button>BACK</button></a>
</body>
</html>
<code type="php"></code>

Re: Execute scipt via Html button using php

Posted: Wed Jun 13, 2018 3:56 pm
by Mick
This board is for support of the phpBB bulletin board software not general PHP support. PHP Support may be better for you.

Re: Execute scipt via Html button using php

Posted: Tue Jun 19, 2018 6:02 am
by yash1947
I feel that there is some issue in logic ?