How to end a user session in PHP?

I tracked an online user session with an img tag with the code below.

<img src="http://www.somedomain.com/track/login.php" alt="" title="" width="1" height="1" />

Using the code above, I created an administration section to display online users.

Now, for some reason. I have to end the online user session from the administration section.

Can anyone help me on this.

Note:

on user pages, the user session is processed using

if(authenticated) {
 $_SESSION['username']=name;
 $_SESSION['id']=id;
}
+3
source share
6 answers

: , , /, (, md5 ) - , , .

//get current logged in user user - this way we get it as a GET or POST parameter - NOT safe, because the user can modify this parameter - you could get it from the login form for example
$current_user = md5($_REQUEST["user"]); 
// start user sessions like this
ini_set('session.save_handler', 'files');
//load the session of the current user 
$current_user = md5($_REQUEST["user"]);
//set the current session id to the one corresponding to current user
session_id($current_user);
session_save_path("/tmp/sessions/");
session_start();

, md5 , :

$current_user = md5($_REQUEST["user"]);
unlink("/tmp/sessions/$current_user");

,

0

:

session_unset();
session_destroy();
+1

, PHP , :

session_id("<that session id>");
session_start();
session_destroy();

, , . session_id() .

+1

, .

true. , , , .

, . , , .

, . . . .

, , , .

, , , . , , : .

+1
0

, , .

Tudor, , (, , ) - . .

Another way is to write your own session processing classes (see the PHP manual for examples - http://php.net/manual/en/session.customhandler.php ) and store the session data in files and / or databases. In other words, using your custom session handlers, I think your task will be easier.

0
source

All Articles