joebloggs1987 Posted May 31, 2009 Share Posted May 31, 2009 Hello. I need help creating a dynamic forum signature. I need the signature to display how many people are online at www.rotarychat.com if that is possible. I only know basic php, so this is a bit out of my knowledge. Thankyou. Quote Link to comment https://forums.phpfreaks.com/topic/160340-dynamic-forum-signature/ Share on other sites More sharing options...
MadTechie Posted May 31, 2009 Share Posted May 31, 2009 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/160340-dynamic-forum-signature/#findComment-846127 Share on other sites More sharing options...
joebloggs1987 Posted May 31, 2009 Author Share Posted May 31, 2009 Im sorry, im completely confused... ??? I really dont know php that well... Quote Link to comment https://forums.phpfreaks.com/topic/160340-dynamic-forum-signature/#findComment-846179 Share on other sites More sharing options...
MadTechie Posted May 31, 2009 Share Posted May 31, 2009 Look at this http://php-login-script.com/ as a note i have NOT looked at the source so it could be quite bad, but should atleast should get you started Quote Link to comment https://forums.phpfreaks.com/topic/160340-dynamic-forum-signature/#findComment-846359 Share on other sites More sharing options...
joebloggs1987 Posted June 1, 2009 Author Share Posted June 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160340-dynamic-forum-signature/#findComment-846705 Share on other sites More sharing options...
laffin Posted June 1, 2009 Share Posted June 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160340-dynamic-forum-signature/#findComment-846821 Share on other sites More sharing options...
joebloggs1987 Posted June 1, 2009 Author Share Posted June 1, 2009 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', ; 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; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/160340-dynamic-forum-signature/#findComment-847368 Share on other sites More sharing options...
laffin Posted June 2, 2009 Share Posted June 2, 2009 I took another look. Its in the javascript, u can get a list of users from This Link But this seems more like a site for sale than a php project, and if thats the case u shud look into freelancers Quote Link to comment https://forums.phpfreaks.com/topic/160340-dynamic-forum-signature/#findComment-847446 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.