2

I have login page, and after login I have user information related pages. so i don't want to direct access those pages from url. Instead of it will redirect to login page. how can I do that.

my sessions.php page code

<?php

if(!isset($_SESSION)) 
{ 
    session_start(); 
} 
$login_session=$_SESSION['email'];
?>
Mahmood Mohammed
  • 187
  • 2
  • 4
  • 14
  • 5
    Possible duplicate of [How to make a redirect in PHP?](http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php) – Epodax Jan 25 '16 at 10:13
  • Set session variable after login and destroy them after logout..make a separate php file which will check if `$_SESSION` is set..If it is set then do nothing else `redirect` to `login.php` – Rayon Jan 25 '16 at 10:15

1 Answers1

6

in your login page: if user successfully logged-in then set any session variable i.e. $_SESSION['userLogin'] = "Loggedin";

Then each and every page check user loggedin or not by below code:

session_start();
if(empty($_SESSION['userLogin']) || $_SESSION['userLogin'] == ''){
    header("Location: http://example.com/login.php");
    die();
}
Ajay Makwana
  • 2,330
  • 1
  • 17
  • 32
  • Thanks..If my answer was helpful then accept it by clicking right marker and give up vote. This is the best way to appreciate the answer. – Ajay Makwana Jan 25 '16 at 11:03