I am working on php session concept in php. created a login page using jquery and php and created sessions for all pages, when I logged in to the session, I can open the registered URLs on other tabs for which it works fine, but I have a problem logging out.
when I go to one of the open tabs of the browser to the other tabs, it is still done manually if I refresh the pages that are logging out. My requirement is when I go to one of the tabs, the other tabs should automatically log out, not manually.
DB file
<?php session_start(); $con = mysqli_connect("localhost", "root", "","testing") or die ("Oops! Server not connected");
login.php
<?php include 'db.php'; if(isset($_SESSION['username']) && $_SESSION['username'] != '') { <html> <body> <form> <table class="mytable"> <tr> <td>Username</td> <td> <input type="text" name="username" id="username" class="as_input" value="s"/> </td> </tr> <tr> <td>Password</td> <td> <input type="password" name="password" id="password" class="as_input" value="s"/> </td> </tr> <tr> <td></td> </tr> <tr> <td colspan="2"> <input type="submit" name="login" id="login" class="as_button" value="Login »" /> </td> </tr> </table> </form> </body> </html>
welcome home page
<?php include 'db.php'; if(!isset($_SESSION['username']) || $_SESSION['username'] == '') { echo '<script type="text/javascript">window.location = "login.php"; </script>'; } ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="as_wrapper"> <h2> welcome to home page </h2> <a href="logout.php" class="a">logout</a><br><br> <a href='#'>test link</a> </div> </body> </html>
logout.php
<?php include 'library.php'; session_destroy(); unset($_SESSION['username']); unset($_SESSION['password']); echo '<script type="text/javascript">window.location = "login.php"; </script>'; ?>
source share