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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

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.