Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. if (!isset($_SESSION["logged_in"]) || !($_SESSION["logged_in"]))
  5. {
  6.     header('Location: login.php');
  7.     die();
  8. }
  9.  
  10. if (isset($_GET["lights") && $_GET["lights"]=="ON")
  11. {
  12.     update_status("1");
  13.     lights_on();
  14. }
  15. else
  16. {
  17.     update_status("0");
  18.     lights_off();
  19. }
  20. $file = fopen("status.txt", "r") or die("Unable to open file!");
  21. $status = fread($file, filesize("status.txt"));
  22. fclose($file);
  23.  
  24. if ($status == "1")
  25. {
  26.     $status_human = "on";
  27. }
  28. else
  29. {
  30.     $status_human = "off";
  31. }
  32.  
  33. function update_status($new_status)
  34. {
  35.     $file = fopen("status.txt", "w+") or die("Unable to open file!");
  36.     fwrite($file, $new_status);
  37.     fclose($file);
  38. }
  39.  
  40. function lights_on()
  41. {
  42.     $url = 'https://maker.ifttt.com/trigger/lights_on/with/key/bFBqf_HMTHPgIc539EGOJQ';
  43.     $contents = file_get_contents($url);
  44. }
  45.  
  46. function lights_off()
  47. {
  48.     $url = 'https://maker.ifttt.com/trigger/lights_off/with/key/bFBqf_HMTHPgIc539EGOJQ';
  49.     $contents = file_get_contents($url);
  50. }
  51. ?>
  52. <html>
  53. <head>
  54. <title>Light Switcher</title>
  55. <link rel="stylesheet" href="./styles.css">
  56. </head>
  57. <body>
  58.     <p>Welcome <?= $_SESSION["username"] ?>! The lights are <?= $status_light ?>.</p>
  59.     <form method="get">
  60.         <input type="radio" name="lights" value="on" <?php echo ($status == "on" ? 'checked' : '')?>>ON<br>
  61.         <input type="radio" name="lights" value="off" <?php echo ($status == "off" ? 'checked' : '')?>>OFF<br>
  62.         <input type="submit">
  63.     </form>
  64. </body>
  65. </html>
  66. <html>
  67. <head>
  68. <title>Light Switcher</title>
  69. <link rel="stylesheet" href="./styles.css">
  70. </head>
  71. <body>
  72. <p>Welcome <?= $_SESSION["username"] ?>! The lights are <?= $status_light ?>.</p>
  73. <form method = "POST" action="http://meijertom.xyz/index.php?lights_on=true">
  74.     <input class='button' type="submit" value='Lights On'/>
  75. </form>
  76. <form method = "POST" action="http://meijertom.xyz/index.php?lights_off=true">
  77.     <input class='button' type="submit" value='Lights Off'/>
  78. </form>
  79. </body>
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement