Sessions

PHOTO EMBED

Tue Jul 11 2023 01:03:58 GMT+0000 (Coordinated Universal Time)

Saved by @Joe_Devs #php

//INDEX.PHP
<?php session_start();
//when login button pushed
if (isset($_POST['login'])){
//    if username and password not empty
    if (!empty($_POST['username']) && !empty($_POST['password'])){
//        store
        $_SESSION['username']  = $_POST["username"];
        $_SESSION['password']  = $_POST["password"];
//    take you to home.php
        header("Location: home.php");
    }else{
        echo "Missing username or password";
    }
}

?>
  
  
  
  
  //HOME.PHP
  <?php
session_start();
//if logout pressed
if (isset($_POST['logout'])){
//    destroys session
    session_destroy();
//    rerouts you to index
    header("Location: index.php");
}
echo $_SESSION['username'] . "<br>";
echo $_SESSION['password'] . "<br>";;



?>
content_copyCOPY

https://www.youtube.com/watch?v=zZ6vybT1HQs&t=11097s