2

I am having a LAMP Server on my Raspberry Pi. I have a static page to control my home switches. Also, I have a button which load the following php code.

PHP Code:

<?php
   # Session Close
   session_start();
   unset($_SESSION['valid']);
   unset($_SESSION['timeout']);
   
   # Server Shutdown
   system('sudo /sbin/shutdown -h now');
   
   # Redirect Page
   header("refresh:0.1;url=https://www.google.com");
?>
<!DOCTYPE html>
<html lang="en">
   <head>
   </head>
   <body>
      <!-- container -->
   </body>
</html>

The above code is doing: close session, shutdown server and redirect to a page.

This code seems to work fine but with delay... It takes time to load page. Press button and waiting...

I would like to ask if i can have the same result but faster. I need a tweak / speed up... Press button and instantly load redirect page and at the same time do the rest.

YvetteLee
  • 1,057
  • 3
  • 13
  • 27
  • 1
    Change your `header()` call to do a proper redirect `header("Location: https://www.google.com/");`. Delete everything after it, including `?>` and replace it with `session_write_close(); die();` – miken32 Dec 07 '20 at 22:28
  • @miken32 Can you please give an answer below as i am missing something, pls. Any other solution is welcome. – YvetteLee Dec 08 '20 at 14:45
  • See answers to the duplicate question – miken32 Dec 08 '20 at 15:50

0 Answers0