Jump to content

[SOLVED] Recently active users


andrewgarn

Recommended Posts

I have a login system, which stores the login time into a table as last login.

 

What i want to do is display users who logged in recently, or are using the site currently at the bottom of the page.

 

How would i go about doing this? It might use the last login info it might not, any ideas?

 

EDIT:

 

Also as a further question: Is it possible to put conditional formatting in CSS? I want numbers inside a div to be red if they are negative and green if they are positive

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/111534-solved-recently-active-users/
Share on other sites

Regarding the CSS styling:

 

<?php

if ($this==$that) { $class="red"; }
elseif ($this==$that2) { $class="orange"; }
elseif ($this==$that3) { $class="yellow"; }

echo '<span style="font-color:'.$class.';">Hey I\'m a different color font</span>';
?>

 

So youve done it in php instead? I would need if($var < 0) ( $class="red"; )

 

can i put that span around 50 lines of code or need to be individually declared for each echo?

<?php

if ($this==$that) { $class="red"; }
elseif ($this==$that2) { $class="orange"; }
elseif ($this==$that3) { $class="yellow"; }

// assuming you have enabled yourself to parse php within html files:
?>

There were <span style="<?=$class?>">AMOUNT</span> users online. Blah blah.

<?
// do more php stuff, etc.
?>

something simple would be like

 

take away timenow from time logged in then do a simple if time <300 print user.

 

In the database i have lastlogin stored as Datetime - 2008-06-23 20:17:56

 

then i retrieve the time using:

 

$date = date("y-m-d H:i:s");

 

but i minus one from the other i get -2000, why?

It's time in seconds from the unix epoch. So you can compare all of your times with that.

 

<?php

$date=strtotime($lastupdated);

$now=strtotime(NOW);

if ($date>$now) {
      // do this
} else {
     // do that
}

?>

 

My requirement was just to show users active in last certain amount of time, so this fulfils it perfectly :)

<?php

if ($this==$that) { $class="red"; }
elseif ($this==$that2) { $class="orange"; }
elseif ($this==$that3) { $class="yellow"; }

// assuming you have enabled yourself to parse php within html files:
?>

There were <span style="<?=$class?>">AMOUNT</span> users online. Blah blah.

<?
// do more php stuff, etc.
?>

 

couldnt make it work :(

 

you mentioned something about php parsing html, how does it do that?

 

EDIT: nmind made it work using if statements in each class

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.