// You may copy this PHP section to the top of file which needs to access after login. session_start(); // Use session variable on this page. This function must put on the top of page. if(!session_is_registered("username")){ // if session variable "username" does not exist. header("location:login.php"); // Re-direct to index.php } ?>