Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unset a specefic session using session id

I am the administrator of the site. I want unset a particular session, and I know its session id.

The users are just starting the session like this:

session_id("usernumber");
session_start();

Let’s say user A has usernumber "123".

I want to destroy all the values of the user A. User A will not regenerate the sessio_id() after setting that as session_id("123");.

How can I unset destroy only for user A?

like image 689
Sarath Avatar asked Jul 15 '11 07:07

Sarath


3 Answers

Answer by Jack Luo on php.net

$session_id_to_destroy = 'nill2if998vhplq9f3pj08vjb1';
// 1. commit session if it's started.
if (session_id()) {
    session_commit();
}

// 2. store current session id
session_start();
$current_session_id = session_id();
session_commit();

// 3. hijack then destroy session specified.
session_id($session_id_to_destroy);
session_start();
session_destroy();
session_commit();

// 4. restore current session id. If don't restore it, your current session will refer     to the session you just destroyed!
session_id($current_session_id);
session_start();
session_commit();
like image 147
Hardik Sondagar Avatar answered Oct 05 '22 05:10

Hardik Sondagar


Without reverse enginering the session handler....

<?php

session_id($_GET['killsid']);
session_start();
session_destroy() || die "failed to kill";
like image 29
symcbean Avatar answered Oct 05 '22 04:10

symcbean


You could try to get session_save_path() (in this directory session files are stored). When you are using default session names the filename looks like sess_jgimlf5edugvdtlaisumq0ham5 where jgimlf5edugvdtlaisumq0ham5 is user session id so you can just unlink this file unless you dont have permissions to edit those files.

like image 43
Norbert Orzechowicz Avatar answered Oct 05 '22 06:10

Norbert Orzechowicz