0

is it possible to unset session by it's value ?

i have a chat application and it identifies user/pears using session called username , i want to be able to unset each session from admin panel .

i have user session value in admin and i can send it to the chat app to unset that specific user by ajax .

$kick_out = $_post['username'];
if($_session['username'] == $kick_out )
unset( $_session['username']  );

but the thing is i don't want to unset all the $_session['username'] , just the one that has $kick_out value

max
  • 3,614
  • 9
  • 59
  • 107
  • See the answer to this question: http://stackoverflow.com/questions/675913/looping-through-all-a-servers-sessions-in-php + the read the first comment! – Niko May 18 '12 at 11:26

4 Answers4

0

Then make the condition:

if{$_session['username'] == $kick_out} unset( $_session['username']);
0

in your code you are assigning the kickout value , you are not making a comparison against it. if you have a $_SESSIONS["username"] can you var dump it so we get a glue what is it? object?array?multidimensional array?string?

Gntem
  • 6,949
  • 2
  • 35
  • 48
0

You cannot modify other users' sessions. If you want to forcefully logout someone you need to store a flag in your database which is checked on every request from a logged-in user.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • there is no logging in and no database(well at least for users ) . when user opens the page i ask for a nickname and set the session . – max May 18 '12 at 13:23
0

If you want to unset someones session, it's impossible.You can store session id to database and when you want to kick someone, set session id empty and every time check if $_SESSION at user is same as from database where username equal to logged in username..

harisdev
  • 4,146
  • 5
  • 19
  • 25