Jump to content

Recommended Posts

Hi all

 

I am creating a site that has a session based log in. Pretty simple stuff, but the bosses have asked if we can make it so that only 1 person can log into an account at once (ie if someone logs in with a specific acocunt, lock the account and dont let any one else log in)

 

I'v been fiddleing around with session, and various session variables etc. and the only part that I cant figure, is if the user logs in, and closes the browser window, how do I know that the user has logged out.

 

Does anyone have any suggestion, clues or help for me?

 

If you would like a more detailed description of how im handleing my sesssions etc. please just ask.

 

Thanks ;)

Link to comment
https://forums.phpfreaks.com/topic/75759-sessions-in-php/
Share on other sites

one method...

 

add 2 fields to the user database table - call one 'online' type = enum 'y','n' the other 'activity' DATETIME (or INT (11) if you prefere timestamp over datetime).

 

when user logins in update table to mark online as yes and update the time it happened. On each page update the activity time. Ste your self a time period (10 mins or so) and when someone attempts to login check online = 'n' if so login if not check activity was more than TIME PERIOD ago - if it was logem in if not boot em and say user is already logged in.

 

Obviously those whose connection dropped out or closed teh broswser will have to wait to login again.  Make sure you update 'online' to 'n' if they logout.

 

There is a method where you can use the actual sessions on the server but I haven't done it yet and I can't find the article describing it at the moment.

Link to comment
https://forums.phpfreaks.com/topic/75759-sessions-in-php/#findComment-383408
Share on other sites

Cool thanks for the help, but I had pretty much come to the same conclusion. If a user closes their window, they arent going to be able to log in again, until the session has timed out... (big bummer)

I also thought of using a session variable, to store the time (well the last activity on the account) and you pretty much get the same thing, if the user closes the window... (blah blah)

If you talking about using the actual session on the server, you can try this

 

  define("SESSION_TIMEOUT_MINS" , 5);

  $session_path = ini_get("session.save_path");
  if(($pos = strpos($session_path , ";")) !== FALSE)
    $session_path = substr($session_path , $pos + 1);
  $session_path .= "/b";
  if(!file_exists($session_path))
    mkdir($session_path , 0774);

  ini_set("session.save_path" , $session_path);
  ini_set("session.gc_probability" , 100);
  ini_set("session.gc_maxlifetime" , (SESSION_TIMEOUT_MINS * 60)); // seconds
  ini_set("session.cookie_lifetime" , 0);
  ini_set("session.cache_limiter" , "nocache");
  ini_set("session.cache_limiter" , "private");
  ini_set("session.cache_expire" , SESSION_TIMEOUT_MINS); // minutes

 

Pretty much does the same thing (it time the session out after a certain time of inactivity), but same thing, if the user closes the window... blah blah blah

 

Thanks again for your suggestion.

Has anyone else got any ides?

Please help, these sessions are driving me crazy O_o

Link to comment
https://forums.phpfreaks.com/topic/75759-sessions-in-php/#findComment-383415
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.