Jump to content

Recommended Posts

What part you stuck on ?

if your using sessions, you could do something like this:~

 

<?php
session_start();
function countUsersOnline()
{
$count = 0;
$handle = opendir(session_save_path());
if ($handle == false) return -1;
while (($file = readdir($handle)) != false)
{
	if (preg_match("/^sess/i", $file))
	{
		if(file_exists($file)) $count++;
	}
}
closedir($handle);
return $count;
}
?>

 

To display

<?php
$usercount = countUsersOnline();
echo $usercount; 
?>

If you have a look at www.rotarychat.com and quickly login (does not require any registration), you will be able to see in the top left hand corner a 'whos online'.

Basically i just want this in a forum signature.

 

Script is http://bernsteinforpresident.com/software/the-hablator

 

Im just not sure how to put it in a forum sig.

U require more than basic PHP.

Looks like u will need CURL (too pass login info) / preg_match (to get the info from the page/scrape)

 

but scraping pages in this fashion take time, so on a forum signature this can cause a bad situation. if a page/thread you become very active in, loads up.

 

as each posting will perform the scrape (get page contents).

 

Yer best bet is to see if the site owner can create a counter files, or who's online file for such use.

Or to cache the results, and perform the scrape every once in awhile.

 

U require more than basic PHP.

Looks like u will need CURL (too pass login info) / preg_match (to get the info from the page/scrape)

 

but scraping pages in this fashion take time, so on a forum signature this can cause a bad situation. if a page/thread you become very active in, loads up.

 

as each posting will perform the scrape (get page contents).

 

Yer best bet is to see if the site owner can create a counter files, or who's online file for such use.

Or to cache the results, and perform the scrape every once in awhile.

 

Hmmm... ok

 

I am the site owner of www.rotarychat.com if that makes a difference.

 

The users online are stored in a text file.

 

For example, with one person online, the text file contains the following...

 

91a04520c5a7e08a2b49627b0e8fdc58 rxsprint 08:32 AM 06/02/2009 1243895565 Windows MSIE 60.242.66.61 1243895590.98

 

The whole script uses text files rather than a mysql database.

 

 

EDIT:

This is what displays it on the chat page...

 

<div id="users"><a href="#" id="userlistlink"><img src="img/triright.gif" class="tri" style="border: none"><img src="img/tridown.gif" style="display:none; border: none" class="tri"><?php echo $language_whos_online; ?></a>

<div id="userlist" style="display:none;"><?php loadusers(); ?></div></div>

 

EDIT: Also...

 

<?php

define('USERS_ID', 0);

define('USERS_NAME', 1);

define('USERS_LOGIN_TIME', 2);

define('USERS_LOGIN_DATE', 3);

define('USERS_TIMESTAMP', 4);

define('USERS_OS', 5);

define('USERS_BROWSER', 6);

define('USERS_IP', 7);

define('USERS_LAST_PING', 8);

 

require_once('lib/flatfile.php');

 

if(!is_writable('users.txt')) die('Please change the permissions of posts.txt to make it writable!');

 

 

 

//Returns the final user ID

function adduser($desired_username)

{

require_once('lib/browser_detection.php');

$db=new Flatfile();

$db->datadir='';

$all=$db->selectAll('users.txt');

if($db->selectUnique('users.txt', USERS_NAME, $desired_username)!=null)

{

$i='1';

while($db->selectUnique('users.txt', USERS_NAME, $desired_username.$i)!=null)

$i++;

$desired_username=$desired_username.$i;

}

$browser=new Browser;

$newuser[uSERS_ID]=session_id();

$newuser[uSERS_NAME]=$desired_username;

$newuser[uSERS_LOGIN_TIME]=date('h:i A');

$newuser[uSERS_LOGIN_DATE]=date('m/d/Y');

$newuser[uSERS_TIMESTAMP]=time();

$newuser[uSERS_OS]=$browser->Platform;

$newuser[uSERS_BROWSER]=$browser->Name;

$newuser[uSERS_IP]=$_SERVER['REMOTE_ADDR'];

$newuser[uSERS_LAST_PING]=gettimeofday(true);

$db->insert('users.txt', $newuser);

return $newuser[uSERS_ID];

}

 

function removeuser($userid)

{

$db=new Flatfile();

$db->datadir='';

$db->deleteWhere('users.txt', new SimpleWhereClause(USERS_ID, '=', $userid, INTEGER_COMPARISON));

}

 

function idtouser($id)

{

require_once('lib/flatfile.php');

$db=new Flatfile();

$db->datadir='';

$userrow=$db->selectUnique('users.txt', USERS_ID, $id);

if ($id==-1)

return 'System';

else if($userrow[uSERS_NAME]!="") return $userrow[uSERS_NAME];

}

 

function usertoid($username)

{

$db=new Flatfile();

$db->datadir='';

$userrow=$db->selectUnique('users.txt', USERS_NAME, $username);

return $userrow[uSERS_ID];

}

 

function setlastping()

{

$db=new Flatfile();

$db->datadir='';

$db->updateSetWhere('users.txt', array(USERS_LAST_PING => gettimeofday(true)), new SimpleWhereClause(USERS_ID, '=', session_id()));

}

 

function getlastping()

{

$db=new Flatfile();

$db->datadir='';

$userrow=$db->selectUnique('users.txt', USERS_ID, session_id());

return $userrow[uSERS_LAST_PING];

}

 

function loadusers()

{

require_once('lib/flatfile.php');

$db=new Flatfile();

$db->datadir='';

include('settings.php');

$userrows=$db->selectAll('users.txt');

$symbols=array('%u', '%t', '%d', '%o', '%l', '%b', '%i');

foreach($userrows as $userrow)

{

$usersos=$userrow[uSERS_OS];

if(strpos($usersos, 'Windows')!==false)

$ospic='img/windows.gif';

else if(strpos($usersos, 'Mac')!==false)

$ospic='img/mac.gif';

else if(strpos($usersos, 'Linux')!==false)

$ospic='img/gnulinux.gif';

else if(strpos($usersos, 'BSD')!==false)

$ospic='img/bsd.gif';

else if(strpos($usersos, 'Wii')!==false)

$ospic='img/wii.gif';

else

$ospic='img/unknown.gif';

$replacements=array($userrow[uSERS_NAME], $userrow[uSERS_LOGIN_TIME], $userrow[uSERS_LOGIN_DATE], $userrow[uSERS_OS], "<img src='$ospic' />", $userrow[uSERS_BROWSER], $userrow[uSERS_IP]);

echo str_replace($symbols, $replacements, $userlist_format)."<br />\n";

}

}

function purgeoldusers()

{

include('settings.php');

$db=new Flatfile();

$db->datadir='';

$db->deleteWhere('users.txt', new SimpleWhereClause(USERS_LAST_PING, '<', time()-$logout_timeout, NUMERIC_COMPARISON));

}

function updatesession()

{

require('settings.php');

if($_SESSION['sessionlastping']+$logout_timeout<time()|$_SESSION['sessionlastping']==null|session_id()=='')

{

return false;

}

else

{

$_SESSION['sessionlastping']=time();

return true;

}

}

?>

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.