Jump to content

How to find a particular Session


sagsai

Recommended Posts

Hello, please don't laugh at my naive question. I desperately need to know whether it is possible to fetch/find a particular session(associated with a particular logged-in user) from all the session that the server generates(for all those users who are logged-in) at a particular point of time using the session ID or any other means & perform operations on that session like unset/destroy the session.

Link to comment
Share on other sites

Thats a tough question.  The first problem you will run into is that PHP by default stores session information in the /temp folder and then periodically removes old or stale session information.

 

This can be corrected by telling your script to store the session information into a different folder.  First create the new folder and chmod it to 777 so php can write to this folder.  Next set the location of this new folder in your scripts with:

 

session_save_path('Path_to_new_folder');

 

To use and get information from the old ID and set the value with:

session_id('old_Id');

 

Once you've assigned both the session_id and the session_save_path then you can finally start the session with:

session_start();

 

To get the active session id to store for later use the following:

$currentSession = session_id();

 

Also if you want to close a session and start a new one you would need to do this:

session_write_close();
session_regenerate_id();
session_start();

 

Hope this helps

Link to comment
Share on other sites

There has been a few questions about people pushing the limits of sessions so i will explain what their purpose is.

 

Sessions by designed were a way to work in tandem with the older technologly of cookies.  The one major difference being that sessions are stored server side with a linking ID stored on the users computer.

 

The bonus to session over cookies is because your data is stored server side you can customize it make arrays in it store anything you want and know the user won't edit it. 

 

Sessions are by design meant to be short term data storage RAM so to speak for the user to use while navigating the site.  A note book of stuff like when its used to see if you are logged in or to keep your shopping cart data.

 

The actual file of the session really isn't meant to be read, they are meant to be read using the $_SESSION super global and the session function library. 

 

If you need to read the content of the file you are looking at some sort of short term databasing method, mysql or flat filing are strong choices here. 

 

Does this clear stuff up?

Link to comment
Share on other sites

Thank you for your replies. Actually I should have elaborated the question. In my script the admin sometimes bans some users as a result of that action the users who are banned are immediately forcibly logged out. Now since I have to log out the target user from outside of their session I cannot use session_destroy() or session_start() to initiate the session. Actually I have solved the problem by writing session related data in a table & deleting the appropriate row when the user has to be logged out. But I just wanted to know if it was possible to fish the appropriate session using the the session id or any other means from the pool of all the active sessions.

Link to comment
Share on other sites

The actual file of the session really isn't meant to be read, they are meant to be read using the $_SESSION super global and the session function library. 

 

If you need to read the content of the file you are looking at some sort of short term databasing method, mysql or flat filing are strong choices here. 

 

Actually I dont want to access the session related data from the actual file where they are stored because it would complicate the process & there would be enough scope of making a mess of the of the whole thing.

I just wanted to know if there were any way to access/operate on a particular active session from outside since this would have simplified the program logic a lot. anyway, I had to solve the problem by storing the session related data in a database table.

Link to comment
Share on other sites

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.