Forum Moderators: coopster
So some questions i have are:
How are sessions stored on the server. Does the PHP engine create databae tables to handle session data.
Can sessions interfere with each other resulting to a programming bug i.e enter in another existing session belonging to a different user.
Can a session be automatically set to expire after a set amount of time, like cookies can?
any comments welcome.
Julie
The lifetime of a session is set in your PHP.ini file. I think most shared servers have it set to 15mins, after which time it will expire. If you close your browser after creating a session, the session is automatically terminated. If you are after an alternative to keep you logged in, you need to look at cookies.
dc :)
[webmasterworld.com...]
My main concern is the ability to disallow logins by multiple people at a time using the same account. I gues i have to implement that myself however because sessions will not manage that for me.
I was thinking of setting a boolean field called "logged" in the MySQL database and change that to true when someone logs, and back to false again when he logs off. the only thing is what would happen if he closes the browser without logging out. That would log him out.
is there a function that could check if a particular session is expired or not? I could ceate anothe field in the database storing the session hash code, then on his next log-on, check wether the session corresponding to the hashkey is still valid.
Any comments?
Julie
Easy way to prevent any kind of session conflict with your users is to set the session variables that are something unique to that particular visitor. Maybe username or e-mail address? Or both. Then query your database based on these variables. As the data is unique, no two users can be the same.
To check whether a session variable already exists, do something like:
if ((isset($_SESSION['username'])) && (isset($_SESSION['email'])))
{
return true;
}
else
{
return false;
}
session_cache_expire()[be2.php.net]; you might also be able to set this a bit more globally in php.ini or in an htaccess file, check the page on
ini_set()and you can see all the nice configuration values. (found it - here [be2.php.net]). I believe default is 180 minutes.
One way to do what you're asking, which will have a fairly big drawback: you'll want to have a field in this same row of your db 'last_access' which is updated with each pageview, and shows the last access date/time of the user. When a user tries to log in, if the field shows the user to be logged out, or the last_access shows that the session would be expired, the user is allowed to log in. Drawback: if they've nuked their cookies, or are url-based sessions, and try to log back in inside this session expire time, they get a message that they won't be able to log in for x minutes, and some might get irritated. However, if security is important, a little irritation is relatively trivial.
It all depends how you syntax your code. So long as you are pulling data based on something unique you should have no problems. On my own site that I am not redesigning, email and usernames are unique so no two users can have the same ones. Then I just query the database based on these two values.