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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.