I want to prevent the user from directly accessing to a page called member.php, and whenever he tries i redirect him to login.php. i tried putting :
session_start();
$_SESSION['fromLogin']='true';
in login.php and :
session_start();
if($_SESSION['fromLogin'] == 'false'){
header('location: login.php');
}else{
$_SESSION['fromLogin']='false';
}
in member.php. It works but when i'm in member.php and i refresh the page it takes me to login.php. i want to stay in member.php. Thanks !
Has the user already login and you want to prevent him from the member.php or he has not login yet. If he has already login, then you should create a role in you database (admin and non_admin) then you collect that role when login. $_SESSION['role']=$row['role']; Then you created a separate admin authentication then include it in the member.php file if($_SESSION['role']!='admin'){ redirect code here }
But if the user don't login, that one is normal athentication if($_SESSION['role']==NULL || $_SESSION['role']==false ){ redirect code here }
Hope it helps you in some way.