//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>";; ?>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter