HaLo2FrEeEk Posted May 20, 2007 Share Posted May 20, 2007 Hey, I'm still writing the code for my school's vote server and it's nearly complete, but I'm having a problem. I have all the data being stored in session variables, so when the student puts in his student ID, it passes it from one page to the next. After the student votes, I use a function called logout that checks if the vote was counted, then uses session_unset($_SESSION['studentID']) and I also have a place that passes an error through session to let the user know of various problems with their login, such as if they have already voted, if voting is disabled, or if there are no candidates to vote on. The problem I am having is when I use session_unset, it unsets ALL session variables, not just the ones I want. php.net says not to use session_unregister if register_globals is disabled, which it is. What else can I do? I need to be able to unset only $_SESSION['error'] (the returned error message) and $_SESSION['studentID'], instead of unsetting the whole session. EDIT: Could I use named sessions? And destroy the named session for students and admins seperately? Could someone tell me how to do this. Quote Link to comment Share on other sites More sharing options...
radar Posted May 20, 2007 Share Posted May 20, 2007 I had my setup so it was like this... i had 3 different types of people who would be logged in, and for testing purposes i had to login to all 3 on the same machine and so i setup my sessions like this: $_SESSION['admin'] = logged in admin array $_SESSION['rater'] = logged in rater array $_SESSION['user'] = logged in user/student array then to destroy a certain one i would use session_destroy('admin'); or whatever i named the session. Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted May 20, 2007 Author Share Posted May 20, 2007 Can you elaborate a little bit, setting $_SESSION['admin'] would only set the session variable admin, you can't call session_destroy(admin) becuase session_destroy doesn't accept modifiers like that. Did you mean naming the session? Could I name the session for student login like this: session_start(); session_name("student"); Then the one for admins would be: session_start(); session_name("admin"); Then to destroy each one, I could simply do session_unset() on whichever one I am working on? Can someone please help me understand this better. Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted May 20, 2007 Author Share Posted May 20, 2007 Also, I'm on a tight schedule, I have to present this on tuesday, but I only have a few more hours to work on it. Quote Link to comment Share on other sites More sharing options...
Glyde Posted May 20, 2007 Share Posted May 20, 2007 As long as you have called session_start() on the page, you should be able to just do unset($_SESSION['sessionname']) to have it both removed from the $_SESSION array but also removed from the temporary session file. Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted May 20, 2007 Author Share Posted May 20, 2007 I call sesssion_start on all my pages, but session_unset doesn't accept variables, php.net's description looks like this: session_unset — Free all session variables void session_unset ( void ) You can't only destroy one variable, you have to destroy them all, but it doesn't actually destroy the session. GAH EDIT: Jeez, I feel dumb, I didn't see that there was a difference between session_unset and unset, I thought that unset was just an alias for session_unset. Thank you for your help, I will test this and get back to you if I need more help. Thank you so much, you're a life saver, everyone that helped. : ) Quote Link to comment Share on other sites More sharing options...
Glyde Posted May 20, 2007 Share Posted May 20, 2007 I didn't say use session_unset, just simply use unset() on the $_SESSION variable. unset($_SESSION['sessionname']); Quote Link to comment Share on other sites More sharing options...
trq Posted May 20, 2007 Share Posted May 20, 2007 I need to be able to unset only $_SESSION['error'] (the returned error message) and $_SESSION['studentID'], instead of unsetting the whole session. <?php session_start(); unset($_SESSION['error']); unset($_SESSION['studentID']); ?> Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted May 21, 2007 Author Share Posted May 21, 2007 I know, read my edit, I feel dumb. Such a simple mistake. It's fixed now, thank you all. 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.