Skip to content

Instantly share code, notes, and snippets.

@tdack
Last active December 27, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdack/7345379 to your computer and use it in GitHub Desktop.
Save tdack/7345379 to your computer and use it in GitHub Desktop.
Simple php script to run a shell command on a server when a button is pressed and return the result.
<?php
$output = array();
$retvar = "";
if ($_GET['run'])
{
// 2>&1 redirects STDERR to STDOUT
exec("/bin/date 2>&1", $output, $retvar);
}
?>
<html>
<head>
<title>Date</title>
<style>
button{
height:100px;
width:200px;
margin: -50px -100px;
position:relative;
top:15%;
left:50%;
}
</style>
</head>
<body>
<?php
if ($_GET['run'] && $retvar == 0)
{
?>
<hr />
<pre>
<?php
foreach ($output as $text)
{
echo "$text\n";
}
?>
<hr />
</pre>
<?php
} else {
?>
<button onclick="window.location.href='?run=true'">Show Date</button>
<?php
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment