sagsai Posted December 13, 2007 Share Posted December 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted December 13, 2007 Share Posted December 13, 2007 log on using that perticular session ID and call session_destroy(); Quote Link to comment Share on other sites More sharing options...
lachild Posted December 13, 2007 Share Posted December 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 13, 2007 Share Posted December 13, 2007 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? Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted December 13, 2007 Share Posted December 13, 2007 Couldnt have said it clearer cooldude. Sessions are for a very shrot time usage. If you want users to stay logged in for a long time use cookies. Or spend 4 hours modifing session data. Your choice Quote Link to comment Share on other sites More sharing options...
sagsai Posted December 14, 2007 Author Share Posted December 14, 2007 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. Quote Link to comment Share on other sites More sharing options...
sagsai Posted December 14, 2007 Author Share Posted December 14, 2007 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. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 14, 2007 Share Posted December 14, 2007 really all you need in your session is a link back to the database like a UserID or primary key of some sorts. Then update your database from remote and they will get the update on a requery Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.