Jump to content

How to create a list of online players


studygirl15

Recommended Posts

Have a table with `Username` and `Unixstamp` or someting. Then record the unix stamp of each player in the database on every page visit.

 

Then work out who's online by fetching all rows with a `Unixstamp` >= time() - 600 or whatever limit you want to time people out with.

Lol.

 

Uhh...ok,

Make a table.

 

On each page request, make a query that updates a field with a timestamp.

 

Then you can determine whether a user is online by checking when they last requested a page.

 

That's what I do on my site. It's pretty straight forward.

 

But yeah, have a go. If you get stuck with something specific, just post back.

ok...

 

so.. i make a table... then i put some code.. which i can find on google.. on the top of all like 40 pages i have made... and the code reads the cookie of the user.. to see which one it is.. and then it like does something magical.. and bam there is a time in the table.. and after how many seconds.. the time thingy expires and disapeers.. and everyime the user visits a new page.. it updates the time thingy...

 

correct?

Kind of...

 

Ok, make one file with something like this in:

$username = $_COOKIE['username'];
$timestamp = time();
mysql_query("INSERT  INTO `user_timestamps` (`username`, `timestamp`) VALUES ('$username', '$timestamp') ON DUPLICATE KEY UPDATE `timestamp`='$timestamp'");

And include that on every page. Then you can figure out who's online with something liek this:

 

$time = time() - $limit;//$limit is how many seconds you allow users to not have made a page request before they are considered "offline"
$sql = mysql_query("SELECT * FROM `user_timestamps` WHERE `timestamp`>='$time'");
//do whatever...

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.