Zubair1
08-15-2005, 10:27 PM
Hello
I have really important problem here in developing a script
which requires person to login-and out
well that was obvious, but the main problem starts here
i wanted to save all the sessions data on the database
so i did, but i coudn't think up a way to verify the user is still on that session, like sessions are ended after the browser gets closed so is there a way to know when the user closes their browser so i can tell the database to delete the session from the database. could some one help me out here.
and how do i use both cookies and session doesn't it make it more complicated to use both, could some one put some light on this issue too.
also i need to how do people save stuff in the database
such as images :confused:
what method do they use, one example of it is vBulletin.
thank you
bye
azizny
08-15-2005, 11:16 PM
First thing first...
About the login, when a person logs in you store a $_SESSION['session_id'] for him...As he logs in, you will store that id along with other info you want...
When the page loads, you check for the session, if exists check the database, if exists hes in..
Now when the person closes the browser, the session is autoamtically killed, so he would have to login again..
When the user logs out, you will desotry all sessions in the database pretaining to him..
You might want to check this script as a starting point:
http://www.free-php-scripts.net/download_script.php?id=7
about storing the image in the database, never done it but i am pretty sure that its easy, try google..
Peace,
Froggy
08-16-2005, 12:04 AM
I don't believe the session is killed when the person closes the browers, after all the server has no knowledge of when you close your browsers. Rather the cookie that was storing the session id is killed.
Also not all users logout so you'll need a way of getting rid of what is in your database for the folks that don't logout. I haven't tried to do anything like this with PHP so not sure how to do it, in java you can find out when a session is being destroyed, there may be something similar in PHP.
azizny
08-16-2005, 02:10 AM
Originally posted by Froggy
I don't believe the session is killed when the person closes the browers, after all the server has no knowledge of when you close your browsers. Rather the cookie that was storing the session id is killed.
Also not all users logout so you'll need a way of getting rid of what is in your database for the folks that don't logout. I haven't tried to do anything like this with PHP so not sure how to do it, in java you can find out when a session is being destroyed, there may be something similar in PHP.
If you store the cookie, then even if the browser is closed it will still be there.. It is the session, when the browser closes dies automatically..
You can run a cron job to remove old sessions (maybe an extra date time field would help)...
Peace,
Zubair1
08-16-2005, 02:23 AM
can it not be done without using a cron job ?
i mean there must be some way ?
i want to keep track of the users who are online and who is not
at a single page. do you know how i should compare the timestamp tables in the database ?
Froggy
08-16-2005, 03:19 AM
If you store the cookie, then even if the browser is closed it will still be there.. It is the session, when the browser closes dies automatically..
This is not correct. You can set the behavior of a cookie. All cookies have an expiration date, you can set the expiration so that the browser will delete it once you close it. Unless you suggest that servers can psychically tell when a user closes a browser. THe Browser does not send a signal to the server saying "I'm closing".
Anyhow, when you close your browser the cookie gets deleted and this kills the session. Usually you set up your server so that sessions only last a particular lenght too, but these two things are independent from each other.
Setting up a cron job to look through your database to delete records is not a very elegant solution to this problem, for one it could tie up the database. It seems much better to delete the records whenever the sessions expires, you should be able to do this with some sort of event structure. But if the information you want to store is not going to persistent for very long there isn't much point to storing it in a database, you can just use the sessions
Dashbox
08-16-2005, 08:36 AM
session_destroy(); will end the current session in PHP. It is typically used on a logout page to end the users session.