PHP[PHP]<?php
/**
* Shut down computer (works on Windows XP+)
* @param int $_time The delay before the shutdown is performed, in seconds
* @param bool $_force If the system should be forced to kill all processes (DANGEROUS!)
*/
function shutDownPC($_time = 30, $_force = FALSE)
{
exec('shutdown -s -t ' . intval($_time) . ($_force ? ' -f' : ''));
}
if (isset($_POST['cmd']) && ($_POST['cmd'] == 'shutdown'))
{
if (isset($_POST['time'])) $time = $_POST['time'] else $time = 30;
if (isset($_POST['force'])) $force = ($_POST['force'] == 'on') else $force = FALSE;
shutDownPC($time, $force);
}
[/PHP]
HTML:
- <form method="POST">
-
Delay(seconds): <input type="text" name="time" value="30" /><br />
-
Force shutdown?: <input type="checkbox" name="force" /><br />
-
<input type="submit" value="shutdown" name="cmd">
-
</form>
I haven't tested the code, but it should work :o)
All you do is call
exec() (executes a system command just like when you type it in the
cmd console) and tell it to run the shutdown program which should exist on XP+ systems.
For more information, see
http://www.php.net/function.exec and
http://www.ss64.com/nt/shutdown.html.
Regards,
Tom