Jump to content

[SOLVED] Session Destroy when browser closed?


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.