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:
[syntax=php]<?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'];
}
}
?>[/syntax]
[syntax=php]<?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'];
}
}
?>[/syntax]
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
[syntax=sql]SELECT `sessionmame` FROM `sf_sessions` WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`lastlogin`) < 900[/syntax]
something like that anyway.
what id the format of the lastlogin column ?
you can probably do it with just one query
[syntax=sql]SELECT `sessionmame` FROM `sf_sessions` WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`lastlogin`) < 900[/syntax]
something like that anyway.
Re: PHP who is online
Am i going to use timestamps on insert query?
Re: PHP who is online
irfanh94 wrote:Am i going to use timestamps on insert query?
That's up to you It would certainly make the maths easier.
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:
[syntax=php]$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();
}[/syntax]
Echoing the users:
[syntax=php]<?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'];
}
}
?>[/syntax]
[syntax=php]$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();
}[/syntax]
Echoing the users:
[syntax=php]<?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'];
}
}
?>[/syntax]
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.