Jump to content

Crisis? when using cookies or not using logout.php


newbtophp

Recommended Posts

Hey!

 

I have a table...with a column isOnline which is set to 1 when logging in (using login.php)...and 0 when logging out (logout.php), its how I determine whos logged in and whos not (in statistics etc.)

 

Now the problem is if they dont have the remember me enabled..and don't log themselfs out via logout.php (which sets the isOnline to 0)...and close their browser the $_SESSIONS's get destroyed (which means their physically not logged in)...and their isOnline remains at 1 (even though their logged out)

 

Another problem..is if they login with remember me enabled (as they want to remain logged in)....and close their browser or whatever, isOnline will still remain as 1 (theirfore others will think their online).

 

For your info:

In login.php I do an UPDATE query adding the current time generated by time() into the loginTime column...and also setting isOnline to 1.

 

So my question is how can I overcome this, I have the isOnline (1 = logged in, 0 not logged in) and loginTime (which contains the login timestamp)?

 

Cheers

Link to comment
Share on other sites

Ok I've deleted the isOnline as its uneeded.

 

 

So now I have loginTime which is UPDATEd with the current time() (timestamp) upon page load (its added at the top of every page within an include).

 

How would I determine if a specific user is online, how would the query be (im guessing it would be structured like the example below but not sure how the WHERE bit will be)?

 

SELECT user FROM site_table WHERE loginTime IS WITHIN 15 MINUTES FROM CURRENT TIME AND user = 'tester'

Link to comment
Share on other sites

try this

SELECT user FROM site_table WHERE loginTime > (now( ) - ( 15 *60 )) AND user = 'tester'

15 = number of minutes

 

Thanks im going to try it, but wouldn't that mean the loginTime is more then 15 minutes, don't we want it to be loginTime <= 15 (to be within 15 minutes?) or am I totally confused and really dumb  :shy:

Link to comment
Share on other sites

I am removing time from Now now the user, i could of added the time to the user (either works)

 

here is the logical break down

 

EDIT: (think of is as minutes past 12)

 

if

loginTime = 20minutes

and

Now = 30minutes

 

then 

loginTime > (Now - 15) =

20 > (15) = true

 

 

if

loginTime = 10minutes

and

Now = 30minutes

 

then 

loginTime > (Now - 15) =

10 > (15) = false

 

Link to comment
Share on other sites

I am removing time from Now now the user, i could of added the time to the user (either works)

 

here is the logical break down

 

EDIT: (think of is as minutes past 12)

 

if

loginTime = 20minutes

and

Now = 30minutes

 

then 

loginTime > (Now - 15) =

20 > (15) = true

 

 

if

loginTime = 10minutes

and

Now = 30minutes

 

then 

loginTime > (Now - 15) =

10 > (15) = false

 

Ok great, but one thing wouldn't now( ) be UNIX_TIMESTAMP() instead or $time ( and $time is assigned to $time = time(); )?

Link to comment
Share on other sites

Now would be a UNIX_TIMESTAMP but all dates and times in MySQL are stored as UNIX_TIMESTAMP's and just converted for display, also if you set the time via MySQL then you should use Now() if you set it via PHP time() then you could use time()

 

loginTime is set using php's time()...

 

so for checking the total users online, would the following work?

 

<?php
$time = time();
$result = mysql_query("SELECT user FROM site_table WHERE loginTime > ($time - ( 15 *60 ))");
//mysql_num_rows etc..

Link to comment
Share on other sites

Now would be a UNIX_TIMESTAMP but all dates and times in MySQL are stored as UNIX_TIMESTAMP's and just converted for display, also if you set the time via MySQL then you should use Now() if you set it via PHP time() then you could use time()

 

loginTime is set using php's time()...

 

so for checking the total users online, would the following work?

 

<?php
$time = time();
$result = mysql_query("SELECT user FROM site_table WHERE loginTime > ($time - ( 15 *60 ))");
//mysql_num_rows etc..

 

Tested that and that works. solved. cheers MadTechie

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.