Imagine you have a page which you want accessible by admin or logged-in user.
You need redirect not Logged in users, if they directly access page’s url. there is a simple trick to that.
After user logged-in, add session:
1 2 3 4 5 6 7 8 | <?php session_start(); $_SESSION['loggedin'] = 1; ?> |
and add this code to any pages you want only accessible bu user or admin:
1 2 3 4 5 6 7 8 9 10 11 12 | <?php <?php session_start(); if( $_SESSION['loggedin'] != 1 ) { header('Location: /register.php'); exit; } ?> |
So every time users check that page, php search for that session, and if its not exist, redirect user to other pages like registration page, home or login page.