Reputation: 1090
i have one page with a navbar button on top. Also, i use one sonoff wifi switch to power on/off one lamp.
I am trying to make this task order to work.
Code power_off.php
<?php
session_start();
unset($_SESSION['valid']);
unset($_SESSION['timeout']);
header( "url=http://192.168.2.2/cs?cmnd=Power%20Off" );
header( "refresh:2;url=http://www.google.gr/" );
?>
Thank you.
Upvotes: 2
Views: 150
Reputation: 670
Solution modifying the Power Off script:
In your entry script:
<?php
session_start();
unset($_SESSION['valid']);
unset($_SESSION['timeout']);
header( "Location: http://192.168.2.2/cs?cmnd=Power%20Off" );
?>
then at the end of that file, the one that makes the poweroff you add
sleep(2); //if you want to wait 2 seconds...
header( "Location: http://www.google.gr/" );
exit;
Solution with CURL:
<?php
session_start();
unset($_SESSION['valid']);
unset($_SESSION['timeout']);
//Initialize cURL.
$ch = curl_init("http://192.168.2.2/cs?cmnd=Power%20Off");
//Execute the request.
curl_exec($ch);
//Close the cURL handle.
curl_close($ch);
sleep(2); //wait for 2 seconds. Remove if not needed.
header( "Location: https://www.google.com" ); //redirect to Google
exit;
?>
Upvotes: 4