Jump to content

Users Online Script.


Zepo.

Recommended Posts

You are looking for php startsession(); you can find this in the php maual at php.net

 

startsession() doesn't exist, I think your thinking about session_start()...although I'm not sure how that relates to the question asked.

 

Just do a google for  "PHP online users tutorial", tons of results come up for this topic.

Link to comment
Share on other sites

If you want to know how many users are online, this is what you need to do.

 

  • Put a datetime field in the users table called "last_active"
  • On your header page, put an update query that will update that field for that specific user to the current date/time.

 

Now on your online users page, do a query like this

SELECT username FROM users WHERE last_active > (NOW - INTERVAL 5 minute)

 

That will get every user (registered) thats been active within the last 5 minutes.

Link to comment
Share on other sites

Not to jack this thread or anything, but would the query work like this as well?

 

SELECT username FROM users WHERE last_active == (NOW)

 

To show who is online at that moment, and not the last 5 minutes?

 

You only use one equal sign in MySQL, other than that though, that would get anyone online at that EXACT moment which would be pretty pointless as it would be hard to catch people who were being active.

Link to comment
Share on other sites

I'm not exactly sure how to use the MySQL update query with date/time...

 

the query is:

 

mysql_query("UPDATE username SET last_active = '?'
WHERE username = '$username'");

 

Is that somewhat right? the ? of course signifying, I don't know what to do... ???

 

Link to comment
Share on other sites

//Last Active Update
if(isset($_COOKIE['user'])){
$timestamp = time();
mysql_query("UPDATE teams SET lastactive='$timestamp' WHERE id='{$_COOKIE['user']}'") or die(mysql_error());
}

 

Is the code

The lastactive field is int(15)

 

Doesnt wanna update for some reason... no errors either....weird.

Link to comment
Share on other sites

//Last Active Update
if(isset($_COOKIE['user'])){
$timestamp = time();
mysql_query("UPDATE teams SET lastactive='$timestamp' WHERE id='{$_COOKIE['user']}'") or die(mysql_error());
}

 

Is the code

The lastactive field is int(15)

 

Did that work for you? If not, change you field to a datetime.

Link to comment
Share on other sites

Ok, now how would i go on to tackle pulling from the database's users last updated within 300 second.... any ideas?

I was thinking something like this, but idk how to use inequalities like that...

$timestamp = time();
$timeout = $timestamp-$timeoutseconds;
$uonline = mysql_num_rows(mysql_query("SELECT teamid FROM teamsonline WHERE lastupdated>$timeout"));

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.