Session Trauma

Hi!
Whenever I close the browser without logout, the session stays as it was before.Is there any way out to automatically destroy session after some time??
I found the following code on internet but cudnt understand what is $_SESSION[‘last_seen’]

<?php
session_start();
if(isset($_SESSION['last_seen']) && (time() - $_SESSION['last_seen']) > 1800) {
    session_destroy();
}
else {
    $_SESSION['last_seen'] = time();
}
?>  

Sessions automatically get destroyed by the browser upon exit, unless you set a cookie or changed the session expire time via your php.ini file its not possible for it to still exist.

As for the code above last_seen is the array key for the session, it sounds to me like you are fairly new to this and i recommend you read through this to get a better understanding of them.

I commented the code below, which should help.

Thx for your help.But still cudnt understand wts “last_seen” variable? Should I have an extra field in database to track the session??

Like i said above last_seen is the array key in the super global $_SESSION, there is no database involvement with sessions unless you want to track a users movement around your website. Again it sounds like you are fairly new to all of this and i do recommend you read the link i gave you as it will help.

Okey SgtLegend.I got it now.Thx a lot :slight_smile: