Skip to content
Advertisement

PHP calling python script and button disappear after clicked in php

i have a python script, that can be called from PHP

start.php

    <html>
 <body>
   <form method="post">

    <input type="submit" value="Start" name="GO">
   </form>
 </body>
</html>

<?php
    if(isset($_POST['GO']))
    {
        shell_exec("sudo python3 /start.py");
    }
?>

how do I make the button disappear if the service is running already? or make a popup windows saying its already running when user tried to click again?

i have another php where it can check the service running or not

status.php

<?php
exec("ps aux | grep -v grep | grep  sudo", $psOutput);
if (count($psOutput) > 0) {
    echo "RUNNING";
}
else{
    echo "not running";
}
?>

Advertisement

Answer

managed to disable the button by adding below code

<input type='submit' <?php if(count($psOutput) > 0) {?> disabled="disabled" <?php } ?> name='GO' value='Start' >

maybe it will help someone else.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement