Redirect to log in page if session does not exist in PHP -
so have page can accessed if user logged in. if not, redirected home page (if user visits page directly). want do, redirect user login page, , if login successful, redirected page.
basically , in simplified way, concepts are:
first, start session inside pages using sessions:
session_start();
then, check in pages:
if(!isset($_session['is-user-logged'])){ header("location: login.php"); exit; }
in login in page:
if($_post){ // .. process form here , check if user submitted valid credentials. $_session['is-user-logged'] = 1; header("location: home.php"); exit; }
on logout page:
session_destroy(); header("location: login.php"); exit;
Comments
Post a Comment