Jump to content

Recommended Posts

I am having  a bit of trouble finding out whether a user is logged in or out so that i can display a lit of the registered users online.

 

I have this section of the code:

	
$query = "DELETE FROM online WHERE username = '".mysql_real_escape_string($_SESSION['username'])."';";
mysql_query($query);
$query = "INSERT INTO online ( username, time ) VALUES ( '".mysql_real_escape_string($_SESSION['username'])."', '".time()."' );";
mysql_query($query);
mysql_close($database_connection);
}

 

What kind of Session will i need at the top to find out if they are logged in?

I tried using:

session_start();
if($_SESSION['s_logged_n'] == 'true'){

 

But that does not work. I believe i need to verify the users Username and password through the Session function.

 

How would i do this?

Link to comment
https://forums.phpfreaks.com/topic/153164-logged-in-online/
Share on other sites

Yes i have a small section that displays in the login that adds to the db at what time they login, and also one for when they log out.

But this part here displays on every page to see if the session is still active. So what SESSION function would i use at the top of this script to get the session?

Link to comment
https://forums.phpfreaks.com/topic/153164-logged-in-online/#findComment-804578
Share on other sites

if($_SESSION['s_logged_n'] == 'true'){

where di you come up with that?  there are no predetermined $_SESSION variables in PHP .. that i know of anyways.

 

session vars are what YOU make them.

 

what i would do is for every successful login, create a session like so :

//upon successful login .. meaning, have this $_SESSION var declared within your login script.
$_SESSION['logged_in'] = true;

now, you can use throughout the site as :

if ($_SESSION['logged_in'])
{
     //do member stuff;
} else {
     //no access.
}

Link to comment
https://forums.phpfreaks.com/topic/153164-logged-in-online/#findComment-804594
Share on other sites

I already have all that.

 

What i was wanting was to constantly update a list of every user that is currently logged in so i could display a list of logged in users.

 

if($_SESSION['s_logged_n'] == 'true'){

That can be used quite well on a page that can only be accessed by users that are logged in.

Does the same as what you said:

if ($_SESSION['logged_in'])

Link to comment
https://forums.phpfreaks.com/topic/153164-logged-in-online/#findComment-804598
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.