1

You can insert this code fragment at the beginning of each page where you want to monitor the user session.

<?php
session_start(); //Initialise the session
// Assign a variable to the username captured in the session
$username2 = $_SESSION['username']; 

//Check whether the session username is empty
if ($_SESSION['username'] == "") 
{ //If it is empty, then redirect the user to the index page
    header("Location:index.php");
}
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.