Re: [PHP] Online Members

2008-12-28 Thread tedd

At 12:07 PM -0500 12/27/08, Daniel Brown wrote:

Check the archives and STFW for examples, but the general gist is
of it is to use $_SESSION tracking with activity checking.  I'm just
typing this in quickly as I go, so it's untested (read: don't copy and
paste for production), but here's a simple example (you should be able
to fill in the blanks easily):


-snip code-

Neat -- thanks.

Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Online Members

2008-12-27 Thread Daniel Brown
On Fri, Dec 26, 2008 at 20:24, Stephen Alistoun
stephenalist...@gmail.com wrote:

 Hi all,

 What is the best way to pick up all the members online on a website?

Check the archives and STFW for examples, but the general gist is
of it is to use $_SESSION tracking with activity checking.  I'm just
typing this in quickly as I go, so it's untested (read: don't copy and
paste for production), but here's a simple example (you should be able
to fill in the blanks easily):

?php
function m($str) { // Just an alias to shorten typing here.
return mysql_real_escape_string($str);
}

session_start();

// You can add their username if they're logged in, or display
// the count of unauthenticated users active on the site as the
// collective # Guests Online group.
mysql_query(UPDATE `users_online` SET `ip` =
'.m($_SERVER['REMOTE_ADDR']).', `last_active` = '.m(time()).`
WHERE `sess_id` = '.m(session_id()).';

if (mysql_affected_rows() == 0) {
mysql_query(INSERT INTO users_online(sess_id,ip,last_active)
VALUES('.m(session_id()).','.m($_SERVER['REMOTE_ADDR']).','.m(time()).');
}

// Et cetera

// Now, to display users online:
$sql = SELECT username FROM users_online WHERE last_active -
.m(time()).  300;
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo $row['username'].br /\n;
}

// And guests:
$sql = SELECT COUNT(*) AS num_guests FROM users_online WHERE
username='' AND last_active - .m(time()).  300;
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
echo There are .$row['num_guests']. guests online.br /\n;

?

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Unadvertised dedicated server deals, too low to print - email me to find out!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Online Members

2008-12-27 Thread Nathan Nobbe
If you're talking about tracking the number of visitors with presently open
sessions at your website...


 I was just browsing the tutorials form at PHP Developer Network and saw
 this : http://forums.devnetwork.net/viewtopic.php?f=28t=29342

 Looks like it does what (I think) you were trying to describe.


the above link winds up at a dead end,
http://webmonkey.wired.com/webmonkey/04/50/index4a.html

 there are many ways to do this, depending upon how you store the session,
you may be able to crawl a list of them.  w/ the stock session support there
are a number of files in /tmp, which would be a place to start.

however, id probly just drop a counter in the database when a session is
created and remove it when said session is destroyed.  then all youd ever
have to do is lookup that number.

this you could achieve via session_set_save_handler()

-nathan


Re: [PHP] Online Members

2008-12-26 Thread Michael Kubler
Some people will be happy with just a corny 1 liner, other's you'll need 
to invite to dinner, and promise a romantic evening, and show how 
masculine/feminine you are.
But I doubt you'll be able to get that many dates, unless it's a single 
site most will probably already be in a relationship, or are simply not 
interested.


Seriously though, I'm not quite sure what you mean by picking up all the 
members online.
If you mean working out how many people are currently online, then you 
can tail the log files, if you have HTTP auth, and manually work it out, 
or the easier way (that likely keep a track of the last activity from a 
user, and assume they are online if they have had any activity within 
the last 30mins, assuming they haven't logged out.


Hope that helps a little, unless I've completely mis-interpreted the 
question.


Michael Kubler
*G*rey *P*hoenix *P*roductions http://www.greyphoenix.biz



Stephen Alistoun wrote:

Hi all,

What is the best way to pick up all the members online on a website?

Regards,

Stephen