climbjm Posted September 9, 2007 Share Posted September 9, 2007 The Story/Setup: I have an Ubuntu FF Server up and running. However it is very noisy and it sits in my bedroom with the printer and all my other networking stuff. However, if I am not at home... I would like a way for my wife to be able to shut the box off without having to SSH into the box, but instead click a simple link to turn it off. However, nothing has worked so far. Anyone have any ideas? What I have so far: $v = ""; if($_GET['command']=='shutdown') { echo("<h1>SHUTTING DOWN SERVER</h1>"); $loadpage=false; // for something else, ignore this $v .= shell_exec('sync'); $v .= shell_exec('sync'); $v .= shell_exec('shutdown'); echo("".$v.""); } // much later down the road <li><a href="index.php?command=shutdown">Shutdown the Server</a> When I run this... it displays the "<h1>SHUTTING DOWN SERVER</h1>" but does not shut down the server. Quote Link to comment https://forums.phpfreaks.com/topic/68590-help-shutting-down-my-php-server-via-a-link/ Share on other sites More sharing options...
darkfreaks Posted September 9, 2007 Share Posted September 9, 2007 <?php function kill($_GET['command']=='shutdown'){ if(shall_exec::is_running($_GET['command']=='shutdown')){ shell_exec("kill -KILL ,$_GET['command']=='shutdown'"); return true; }else return false; ?> Quote Link to comment https://forums.phpfreaks.com/topic/68590-help-shutting-down-my-php-server-via-a-link/#findComment-344788 Share on other sites More sharing options...
climbjm Posted September 9, 2007 Author Share Posted September 9, 2007 Another Info: Functions I have tried: shell_exec() exec() system() Commands I have tried: halt shutdown reboot sudo halt sudo shutdown sudo reboot Quote Link to comment https://forums.phpfreaks.com/topic/68590-help-shutting-down-my-php-server-via-a-link/#findComment-344791 Share on other sites More sharing options...
climbjm Posted September 9, 2007 Author Share Posted September 9, 2007 I'll try that Dark Freaks and will let you know if it works! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/68590-help-shutting-down-my-php-server-via-a-link/#findComment-344792 Share on other sites More sharing options...
climbjm Posted September 9, 2007 Author Share Posted September 9, 2007 Ok, looking over the code example... that is just to kill a process right? I want it to completely shut down the server. Quote Link to comment https://forums.phpfreaks.com/topic/68590-help-shutting-down-my-php-server-via-a-link/#findComment-344808 Share on other sites More sharing options...
darkfreaks Posted September 9, 2007 Share Posted September 9, 2007 in your code try using exec instead of shell_exec Quote Link to comment https://forums.phpfreaks.com/topic/68590-help-shutting-down-my-php-server-via-a-link/#findComment-344810 Share on other sites More sharing options...
Fadion Posted September 9, 2007 Share Posted September 9, 2007 First u must be sure u are executing commands, as having safe_mode on will stop functions like shell_exec(), exec(), system(), passthru() and ` (backtick operator). Im far from a linux profficient, but not sure apache will have the privileges to run a shutdown command. U can grant those permissions, but again ull face the problem that anyone can shutdown (or whatever) your web server from a simple script. Hope it helped. Quote Link to comment https://forums.phpfreaks.com/topic/68590-help-shutting-down-my-php-server-via-a-link/#findComment-344961 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.