1

So I have been trying to work with session but it seems my code is not working. My session_start() function when creating session is inside of an if statement after validating login from server, not at the start of PHP. The following are my codes:

//Creating sessions
        session_start();
        $_SESSION['last_active'] = time();

        $_SESSION['username'] = 
        $logged_user;

        //redirecting from login page to any page.
        //refresh sets the redirect time.
        header("Refresh: 3; URL=redirect_after_login.php");

The following is the code after redirect:

session_start();
if(isset($_SESSION['last_active']) && (time() - $_SESSION['last_active'])>10)
{
/*
##This if statement checks if the last activity session is set or not
##Then checks if the time is more than 10 minutes.
*/
session_destroy();
header('Location = login.php');}
Rian Zaman
  • 409
  • 1
  • 6
  • 18

1 Answers1

0

I have found the problem with this code. Now I know why my code was not working... In the second code snippet I used header('Location = login.php'); this is wrong. header uses colon(:) not an equal (=) sign. Finally today when I was reviewing my code I saw this error. So the code should be header('Location:login.php');.

Rian Zaman
  • 409
  • 1
  • 6
  • 18