Jump to content

Currently logged in


mbrown

Recommended Posts

this is the actual updating of the field

//user logs-in
include ("database.php");
UPDATE users SET loggedin="Yes" WHERE username = '$userid';

 

 

this is where i want to put it

include ("database.php");		

$userquery = "SELECT username FROM users WHERE loggedin= 'Yes'";

$query = mysql_fetch_assoc(mysql_query($userquery));

if($query[loggedin] == "Yes")
{
     echo $query[username] . " | ";
}

 

on log out

 

include ("database.php");
UPDATE SET loggedin='No' WHERE userid = '$userid';
session_start();
session_end();

Link to comment
Share on other sites

hmm

 

something i have to think about. how the sessions set up i have when the browser is closed the session is closed as well thus the user returning needs to log in. that is how i was taught in a class i took last semester. so the way i did it i think will work. i will though look at your suggestions.

Link to comment
Share on other sites

hmm

 

something i have to think about. how the sessions set up i have when the browser is closed the session is closed as well thus the user returning needs to log in. that is how i was taught in a class i took last semester. so the way i did it i think will work. i will though look at your suggestions.

 

That is true, when browser is closed so is the session. The question you need to ask yourself, is that ok? Let's say that someone is at a public computer in a library, they leave the computer running with the browser open to your site. They essentially created a loop hole, if after 30 minutes another user comes and sees, they will just use that account if they are not nice.

 

However, you may not care to be honest. Most sites that contain shopping carts etc, timeout after 15-20 minutes for this reason. If you do not have sensitive information used for that user, I would say leaving them in until they close the browser is fine.

Link to comment
Share on other sites

how can i set the session length? we did not cover that in my class that i remember.

 

i could just have the session expire after 15 minutes correct? that is what you are saying?

 

Yes, you can set the session timeout in the php.ini config. If you are using this in the db for the currently logged, however, you want that DB entry to expire also like runnerjp said. So, what you do, is create a CRON job or Scheduled Task and run it every 5-10 minutes checking db values. If there is a DB value of lastseen that is more than 15 minutes long you can expire that user in the DB entry. This will not kill their session, without the session timeout. But this will show them as offline if after 15 minutes of inactivity.

 

Hope that makes sense.

Link to comment
Share on other sites

how can i set the session length? we did not cover that in my class that i remember.

 

i could just have the session expire after 15 minutes correct? that is what you are saying?

 

Yes, you can set the session timeout in the php.ini config. If you are using this in the db for the currently logged, however, you want that DB entry to expire also like runnerjp said. So, what you do, is create a CRON job or Scheduled Task and run it every 5-10 minutes checking db values. If there is a DB value of lastseen that is more than 15 minutes long you can expire that user in the DB entry. This will not kill their session, without the session timeout. But this will show them as offline if after 15 minutes of inactivity.

 

Hope that makes sense.

 

what do you mean using this in teh db? you mean if i have a row, etc to specify something like runnerjp stated?

Link to comment
Share on other sites

how can i set the session length? we did not cover that in my class that i remember.

 

i could just have the session expire after 15 minutes correct? that is what you are saying?

 

Yes, you can set the session timeout in the php.ini config. If you are using this in the db for the currently logged, however, you want that DB entry to expire also like runnerjp said. So, what you do, is create a CRON job or Scheduled Task and run it every 5-10 minutes checking db values. If there is a DB value of lastseen that is more than 15 minutes long you can expire that user in the DB entry. This will not kill their session, without the session timeout. But this will show them as offline if after 15 minutes of inactivity.

 

Hope that makes sense.

 

what do you mean using this in teh db? you mean if i have a row, etc to specify something like runnerjp stated?

 

Right, you will have to create a new table or add a column to the user row.

 

So a new table you would have, userid, lastseen  each time a page is called you update that entry to keep the user alive. Then running a background script you can check for inactive/no longer logged in users and delete that row out of the DB if it is > x minutes. That way only users present in that table are shown as being logged in.

 

http://www.google.com/search?hl=en&sa=X&oi=spell&resnum=1&ct=result&cd=1&q=php+who%27s+online&spell=1

 

There are a lot of scripts already made and tutorials on this subject.

Link to comment
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.