I have a simple script to check status of particular comp on local net, and would like to make a popup prompt box showing status, and asking client if he wants to check again in number of seconds. PHP Code looks something like this:
<!DOCTYPE html>
<html>
<head> <meta charset="UTF-8">
</head>
<body>
<?php
$STS = shell_exec('nc -v -z -w 3 10.1.2.3 3389 &>/dev/null && echo "Online" || echo "Offline"');
echo "<h5>Server is currently:<b> $STS</h5></b>";
for ($x = 0; $x <= 10; $x++) {
$STS = shell_exec('nc -v -z -w 3 10.1.2.3 3389 &>/dev/null && echo "Online" || echo "Offline"');
if ( strcmp($STS, "Offline") !== 0) {
function prompt($prompt_msg){
echo("<script type='text/javascript'> var answer = prompt('".$prompt_msg."'); </script>");
$answer = "<script type='text/javascript'> document.write(answer)</script>";
return($answer);
}
$prompt_msg = "Currently Offline. Check Again in how many seconds?";
$delay = prompt($prompt_msg);
if ( $delay > 0 ) {
sleep ($delay);
}
} elseif ( strcmp($STS, "Online" ) == 0) {
echo "<h5>Server is ready! </h5>";
$x = 10;
}
}
?>
</body>
</html>
So I would like the pop-up and when clicked OK to run sleep()
and check
again if cancel it would close and stop. I don't know how to check, if it was clicked Cancel
. Also script seems to hang after first round of loop.