Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if (!isset($_SESSION["logged_in"]) || !($_SESSION["logged_in"]))
- {
- header('Location: login.php');
- die();
- }
- if (isset($_GET["lights") && $_GET["lights"]=="ON")
- {
- update_status("1");
- lights_on();
- }
- else
- {
- update_status("0");
- lights_off();
- }
- $file = fopen("status.txt", "r") or die("Unable to open file!");
- $status = fread($file, filesize("status.txt"));
- fclose($file);
- if ($status == "1")
- {
- $status_human = "on";
- }
- else
- {
- $status_human = "off";
- }
- function update_status($new_status)
- {
- $file = fopen("status.txt", "w+") or die("Unable to open file!");
- fwrite($file, $new_status);
- fclose($file);
- }
- function lights_on()
- {
- $url = 'https://maker.ifttt.com/trigger/lights_on/with/key/bFBqf_HMTHPgIc539EGOJQ';
- $contents = file_get_contents($url);
- }
- function lights_off()
- {
- $url = 'https://maker.ifttt.com/trigger/lights_off/with/key/bFBqf_HMTHPgIc539EGOJQ';
- $contents = file_get_contents($url);
- }
- ?>
- <html>
- <head>
- <title>Light Switcher</title>
- <link rel="stylesheet" href="./styles.css">
- </head>
- <body>
- <p>Welcome <?= $_SESSION["username"] ?>! The lights are <?= $status_light ?>.</p>
- <form method="get">
- <input type="radio" name="lights" value="on" <?php echo ($status == "on" ? 'checked' : '')?>>ON<br>
- <input type="radio" name="lights" value="off" <?php echo ($status == "off" ? 'checked' : '')?>>OFF<br>
- <input type="submit">
- </form>
- </body>
- </html>
- <html>
- <head>
- <title>Light Switcher</title>
- <link rel="stylesheet" href="./styles.css">
- </head>
- <body>
- <p>Welcome <?= $_SESSION["username"] ?>! The lights are <?= $status_light ?>.</p>
- <form method = "POST" action="http://meijertom.xyz/index.php?lights_on=true">
- <input class='button' type="submit" value='Lights On'/>
- </form>
- <form method = "POST" action="http://meijertom.xyz/index.php?lights_off=true">
- <input class='button' type="submit" value='Lights Off'/>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement