Jump to content

[SOLVED] Session Destroy when browser closed?


LostKID

Recommended Posts

Hi i was wondering is there anyway to destory a session after say 60 mins of inactivity or after thr browser is closed? Can i use just sessions? or do i have have to use cookies?

 

I have been looking around and was wondering if this would work.. this is on the login_process.php

define(COOKIE_DIR, '/');
define(COOKIE_MAXLIFE, '1800');
define(GC_MAXLIFE, '1800');
session_save_path(SESSION_PATH);
ini_set('session.gc_maxlifetime', GC_MAXLIFE);
session_set_cookie_params(COOKIE_MAXLIFE, COOKIE_PATH);
session_start();
$_SESSION['auth'] = "yes";
$_SESSION['email'] = $email;
$_SESSION['online'] = 1;

Well, Sessions are automatically destroyed when the browser is closed

Not strictly true. Sessions are destroyed after a period of inactivity.

Unless the browser makes a call to the server when it's closed, then there's no way that PHP running on the server can know that it has been closed.

all you need to do is set the session.gc_maxlifetime to 1800, as for clearing session when the browser is closed, i really don't see the point but you could create a "still here" script that tells the server the client is still active but that seams totally a waste of resource and effort.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.