What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Users Online Script

Users Online Script
Author: Message:
absorbation
Elite Member
*****

Avatar

Posts: 3636
Reputation: 81
– / Male / Flag
Joined: Feb 2005
O.P. Tongue  Users Online Script
I need a quick script for the amount of usersonline :)

code:
<?php
// Configuration
$dbhost = "localhost";
$dbuser = "[to-add]"; // MySQL Username
$dbpass = "[to-add]"; // MySQL Password
$dbname = "[to-add]"; // Database Name
$timeoutseconds = 1200; // length of session, 20 minutes is the standard

$timestamp=time();
$timeout=$timestamp-$timeoutseconds;
$ip = substr($REMOTE_ADDR, 0, strrpos($REMOTE_ADDR,"."));

// Connect to MySQL Database
@mysql_connect($dbhost,$dbuser,$dbpass);
@mysql_select_db($dbname) or die("No db");

// Add this user to database
$loopcap = 0;
while ($loopcap<3 && @mysql_query("insert into useronline values('$timestamp','$ip','$PHP_SELF')"))
{ // in case of collision
$timestamp = $timestamp+$ip{0}; $loopcap++;
}

// Delete users that have been online for more then "$timeoutseconds" seconds
@mysql_query("delete from useronline where timestamp<$timeout");

// Select users online
$result = @mysql_query("select distinct ip from useronline");
$user = @mysql_num_rows($result);

mysql_free_result($result);
@mysql_close();

// Show all users online
if ($user==1) {echo $user.' user online';} else {echo $user.' users online';}
?>



I was using that but my new hosts server does not use it right.

It can be mysql stored or txt file stored I do not care, if anyone could make thid quick script I would appciate it :)

This post was edited on 10-28-2005 at 04:02 PM by absorbation.
10-28-2005 03:44 PM
Profile PM Find Quote Report
Fourjays
Full Member
***

Avatar
Jaguar E-Type

Posts: 134
Reputation: 6
36 / Male / –
Joined: Jan 2005
RE: Users Online Scipt
Idr where I read it, but today I was reading up on making custom session handlers using PHP and MySQL, and they mentioned that one of their most useful purposes is for something like a "Users Online" script.

When a person visits your site, it stores a session in the database. It will remain there until they close their browser, at which point it unsets the session. Then 5 minutes after they have closed their browser, it deletes the session from the database. You would call the number of users online, by counting the number of sessions in the database.

http://www.zend.com/zend/spotlight/code-gallery-w...pen=1&anc=0&view=1
A page on custom sessions.
[Image: msgsig7yx.jpg]
A new range of internet based services... Coming Soon(ish)! - www.fortheinter.net
10-28-2005 03:58 PM
Profile E-Mail PM Web Find Quote Report
absorbation
Elite Member
*****

Avatar

Posts: 3636
Reputation: 81
– / Male / Flag
Joined: Feb 2005
O.P. RE: Users Online Scipt
Yeh that's where my server messes up it seems it cannot store the ip address.

However the mybb one works :S Which is confusing so there must be mulitple ways of storing an ip address :P
10-28-2005 04:00 PM
Profile PM Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: Users Online Scipt
Try changing

$REMOTE_ADDR

to

$_SERVER['REMOTE_ADDR']
10-28-2005 04:06 PM
Profile PM Web Find Quote Report
absorbation
Elite Member
*****

Avatar

Posts: 3636
Reputation: 81
– / Male / Flag
Joined: Feb 2005
O.P. RE: Users Online Script
http://www.msgstuff.com/useronline.php

Ok let's test :P thanks wdz, i'll see if it works ;)

edit: i wov you :kiss:

This post was edited on 10-28-2005 at 04:12 PM by absorbation.
10-28-2005 04:10 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On