PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am attempting to record the login/logout time of a user. I am saving the times in the database(varchar), and I am successful with saving the login time, but the logout time is what I am having an issue with.
You can't really know when the person logs out for sure. To put in a logout time, you'd have to require them to click the "logout" button, and that's not consistent. The best you can do is to set the logout time every time the user loads a page. The database will ultimately hold the time of the last page load of the user.
The point is to record the time when the person click on the logout button/link. I've got it to where it where enter a login time, then when I click to logout it stays NULL, but if I login, it will create a new row(as I need it to do), and when I logout the new record is NULL, but the first record updates the logout time. I tested again, creates a new row, enters the login time, and when I logout, again the first record updates with a new time. It seems that the session is truly never killed, or when I start the session, it believe the session_id is always 1.
I see. Honestly, if I were you, I'd use a combination of the two methods. Otherwise you'll have a lot of sessions that don't have a logout time at all.
But to address your problem more directly, the issue appears to be in your SQL query. In the login page, you set the "login" column (whatever that is), but no "session_id" column. Then you try to access the session row by the "session_id" column later in logout, but it's not defined. And why are you querying for all rows in the logout page?
I reference the login column because I am to enter the persons username in the login column(I should probably change the name from login to username), and I have the session_id to auto-increment when created, and I am hoping that the session would recognize the session_id.
Basically what the logout code does in set the logout time to the first item it grabs from the database. What you want to do is store session_id() in the session_id column in your table.