Sign in to follow this  
shanebo3239

PHP Session Issues

Recommended Posts

Here's kind of a quick rundown of the problem I'm having. I have a little program (first program I've written in any language so bear with me) that allows you to enter, edit, and delete inventory from a mysql database. I want to have spot on the homepage which shows who is logged in currently. I created a database table called "logged_in" which is written to every time a user logs in. I used php to loop through and see what was in that table, and echo the usernames. So it looks something like this: Username: Logged in since: tsmith 10:08am ljones 11:56am This works fine, and they are deleted correctly from the database when they hit my logout link, because in the logout script it deletes them. However, if they just close out mozilla (all of our users use mozilla) then their name stays in the table because no script has been run to do otherwise. We are running RH Enterprise edition with apache on our server. I know sessions are stored in flat files in /usr/lib I believe (i dont have the server in front of me). How do I get php to check for these files and delete the corresponding users when these files are gone?

Share this post


Link to post
Share on other sites
file_exists() ?


Do you need the database for this though? You can store session data in $_SESSION, and then give the session an appropriate timeout, so they'll be deleted automatically. As long as you don't want to store anything hugely complex, php's built-in session handling should work fine, without needing to store session data in your db.

Share this post


Link to post
Share on other sites
Well, its not really a matter of the file existing. The file can still remain, but the contents of it get blown away (That's my fault I shouldnt have even suggested that). Im not really storing the "session" in the database. What Im doing is sending the variable $username into the database each time a user logs in (its a form so I'm just passing it in).

Im not very familiar with this $_session. Could you explain a little more?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this