06 augustus 2019
From the category: Hacks

Switch off the PC using PHP

On my Exergaming PC there is a button in the main menu that turns off the system. It must be able to switch off the system from PHP. PHP? Yes, I use PHP as a web server by executing this in the directory where the games are located:

php -S localhost:80

This page switches off the PC:
<?php
exec("shutdown -h now");
echo("Doei!");
?>

It works because I did this (one time):

sudo chmod +s /sbin/shutdown

After this I can safely pull out the plug. In the BIOS of the NUC (to be shown with F2) it says that it must switch on automatically after a power failure, so plug it in and everything starts up again.
 

Reacties

 

Comment

Name:

Comment:

 
(C) 2019 marcelv
 
Should a website to which I refer fail, I always have a backup.