[UPHPU] Help with project
David Smith
davidsmith at byu.net
Sat Jun 19 15:08:26 MDT 2004
Jonathan Grotegut wrote:
> I am working on a project to start and stop a game server from a web
> page. I am trying to do a button that when clicked will run a bat
> program to start or stop a server.
>
> This is what I have (basicly)
>
> $twl = "C:\\pathtobat\\twladv.bat";
>
> (other code for page)
>
> echo ' <input type="button" value="Start" onclick="' . exec ($twl) .
> '" />';
You probably don't want the exec call in the onClick property of the
input button, but rather in the PHP script that is the action of the
form. Something more like this:
<?php
echo '<form action="game.php" method="post">';
echo ' <input type="submit" value="Start" name="action" />';
echo '</form>';
echo '<form action="game.php" method="post">';
echo ' <input type="submit" value="Stop" name="action" />';
echo '</form>';
?>
And then, game.php looks like this:
<?php
$twl = "C:\\pathtobat\\twladv.bat";
$action = $_POST['action'];
if( $action == 'Start' ) {
echo "Starting...<br />\n";
exec( $twl );
echo "Done!<br />\n";
} elseif( $action == 'Stop' ) {
echo "Stopping...<br />\n";
exec( "c:\something\else.exe" );
echo "Done!<br />\n";
}
?>
That ought to get you pointed in the right direction. The exec() call
should definitely not be in the JavaScript onClick property of the
input. Good luck!.
--Dave
More information about the UPHPU
mailing list