Page 1 of 1
load other template
Posted: Tue May 08, 2012 12:42 pm
by dmallia
So i have 2scripts(to start and stop a server) and 2 templates( 1 with a start button and another with a stop button). I want a do a script that shows the start template when the server is off. Than when a user clicks the start button it executes the script and when the page reloads it loads the template with the stop button. Than if a users decides to click a stop button, the page reloads, execute a script and load the start template.
Any hints on how i can do it?
Re: load other template
Posted: Tue May 08, 2012 1:22 pm
by Christopher
It may be simpler to have one script that submits to itself. Have PHP generate either a Start button that submits a stop parameter or a Stop button that submits a start parameter. Then the script can stop or start based on the parameter.
Re: load other template
Posted: Wed May 09, 2012 12:16 pm
by dmallia
any hints how i can do it?
Re: load other template
Posted: Wed May 09, 2012 4:13 pm
by Christopher
What code to you have now? Post it.
Re: load other template
Posted: Fri May 11, 2012 11:58 am
by dmallia
Code: Select all
<form method="post" enctype="multipart/form-data">
<input type="submit" name="start" value="Start" />
</form>
<?php
include('ssh_con.php');
$stop = 'screen -S test -X quit';
ssh2_exec($con, $stop);
?>
This script stops the server and shows the start button to start again.
Code: Select all
<form method="post" enctype="multipart/form-data">
<input type="submit" name="stop" value="Stop" />
</form>
<?php
include('ssh_con.php');
$start = 'screen -d -m -S test /home/servers/ts/test/ts3_server';
ssh2_exec($con, $start);
?>
This script is to start the server and shows the stop button.
Till now i only made this code.
Re: load other template
Posted: Fri May 11, 2012 10:49 pm
by Christopher
There are many ways to do this, but the simplest would be to add action="" to each form:
stop.php
Code: Select all
<form action="start.php" method="post" enctype="multipart/form-data">
<input type="submit" name="start" value="Start" />
// the rest of the stop script
start.php
Code: Select all
<form action="stop.php" method="post" enctype="multipart/form-data">
<input type="submit" name="stop" value="Stop" />
// the rest of the start script
Re: load other template
Posted: Fri May 18, 2012 11:59 am
by dmallia
sry to posting late but i was a little bit busy with coding.
Thanks for your help till now it's working fine

Re: load other template
Posted: Sat May 19, 2012 8:53 am
by dmallia
Now i have a problem. When example i press the start button and loads the stop.php it executes some coding. When refreshing it it executes the coding again. Is there anything i can do so if a user refreshes the code will not be executed again.
Problem solved too using mysql variable.