load other template

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

load other template

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: load other template

Post 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.
(#10850)
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

Re: load other template

Post by dmallia »

any hints how i can do it?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: load other template

Post by Christopher »

What code to you have now? Post it.
(#10850)
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

Re: load other template

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: load other template

Post 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
(#10850)
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

Re: load other template

Post 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 :D
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

Re: load other template

Post 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.
Post Reply