PHP who is online
PHP who is online
How can i echo the users who online on my site (who is logged in)..
Re: PHP who is online
You would have to do something like store the last active time in a table, update it every page load. And to get the active users do a query to get the users where this time is within 5 minutes.
Re: PHP who is online
Ok, and how i can echo time(); to the real time, example: 19:34
Re: PHP who is online
Look, i think to do design of table like this:
session name, ip adress, lastlogin (including refreshing the page). I after this i think i should do this:
$timelogin = actual time - lastlogin
and if $timelogin > 15 minutes echo nothing, else get from the database all users who logged in for 15 minutes.
Is this correct? Is this the way i should do the "who is logged in"?
session name, ip adress, lastlogin (including refreshing the page). I after this i think i should do this:
$timelogin = actual time - lastlogin
and if $timelogin > 15 minutes echo nothing, else get from the database all users who logged in for 15 minutes.
Is this correct? Is this the way i should do the "who is logged in"?
Re: PHP who is online
Huh, i understand it now. Im going to code it, and post it here again, to see is it correct.
Re: PHP who is online
Ok, here is the code:
<?php $actualtime = date("h:m"); $query = mysql_query("SELECT * FROM `sf_sessions`"); while ($row = mysql_fetch_assoc($query)) { $pastime = $row['lastlogin']; $timeloggedin = $actualtime - $pastime; if ($timeloggedin >= 15) { echo 'Users logged in for 15 minutes:' $row['sessioname']; } } ?>
Re: PHP who is online
Hmm, you will need to use a timestamp to do the math.
what id the format of the lastlogin column ?
you can probably do it with just one query
what id the format of the lastlogin column ?
you can probably do it with just one query
SELECT `sessionmame` FROM `sf_sessions` WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`lastlogin`) < 900something like that anyway.
Re: PHP who is online
Am i going to use timestamps on insert query?
Re: PHP who is online
That's up to you It would certainly make the maths easier.irfanh94 wrote:Am i going to use timestamps on insert query?
Re: PHP who is online
God damn, here is the new problem.
When i put the date like this: date("h:m"); it always repeat same time 09:05..
EDIT: again new problem:
look on the right side of http://brainiac-design.info/probe/sfilms/, i just want to echo one time user, not to repeat.
When i put the date like this: date("h:m"); it always repeat same time 09:05..
EDIT: again new problem:
look on the right side of http://brainiac-design.info/probe/sfilms/, i just want to echo one time user, not to repeat.
Re: PHP who is online
Imoporting the users:
Echoing the users:
$member = $_SESSION['member']; if ($member) { $time = time(); $ipadress = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO `sf_sessions` (sessionname, ipadress, lastlogin) VALUES ('$member','$ipadress','$time')"); echo mysql_error(); }
Echoing the users:
<?php $currentime = time(); $query = mysql_query("SELECT `sessionname` FROM `sf_sessions` WHERE '$currenttime' - `lastlogin` < 900 ORDER by lastlogin desc"); echo mysql_error(); if ($query) { while ($row = mysql_fetch_assoc($query)) { echo $row['sessionname']; } } ?>
Re: PHP who is online
Are you inserting that row on every page load ? because it should be an UPDATE.
the "ON DUPLICATE KEY UPDATE" syntax may be of use
the "ON DUPLICATE KEY UPDATE" syntax may be of use
Re: PHP who is online
Thanks good, and also thanks to you. I fixed it.