Online users in footer 4 PLigg


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. A few people asked for a users online script/mod. This is how i did it for a friend. Btw it doesn't matter if you use pligg 1.1 or 9.9 it always works.
  2.  
  3. 1. Make a sql base/table.
  4.  
  5. CREATE TABLE `useronline` (
  6. `timestamp` int(15) NOT NULL default '0',
  7. `ip` varchar(40) NOT NULL default '',
  8. `file` varchar(100) NOT NULL default '',
  9. PRIMARY KEY (`timestamp`),
  10. KEY `ip` (`ip`),
  11. KEY `file` (`file`) ) TYPE=MyISAM;
  12.  
  13. 2. Make a directory in 3rdparty call it onlineusers, put in this directory the online.php script. Name the script below online.php and put it in onlineusers.
  14.  
  15. <?php
  16. $dbhosta = "localhost";
  17. $dbusera = "xxxxxxxxxxxxxxxxxxx"; // MySQL username
  18. $dbpassa = "xxxxxxxxxxxxxxxxxxx"; // MySQL password
  19. $dbnamea = "xxxxxxxxxxxxxxxxxxx"; // database name
  20.  
  21. @mysql_connect($dbhosta,$dbusera,$dbpassa);
  22. @mysql_select_db($dbnamea) or die("Huh dude no dbase!");
  23.  
  24. $timeoutseconds = 120; //2 minutes = 120 seconds
  25.  
  26. $timestamp=time();
  27. $timeout=$timestamp-$timeoutseconds;
  28. $ip = substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'],"."));
  29.  
  30. $loopcap = 0;
  31. while($loopcap<3 && @mysql_query("INSERT INTO useronline VALUES('". $timestamp ."','". $ip ."','". $_SERVER['PHP_SELF'] ."')"))
  32. { // In geval van error
  33. $timestamp = $timestamp+$ip{0}; $loopcap++;
  34. }
  35.  
  36. @mysql_query("DELETE FROM useronline WHERE timestamp<". $timeout);
  37.  
  38. $result = @mysql_query("SELECT DISTINCT ip FROM useronline");
  39. $user = @mysql_num_rows($result);
  40.  
  41. mysql_free_result($result);
  42.  
  43. echo ($user == 1) ? $user ."" : $user ."";
  44. ?>
  45.  
  46. 3. Edit online.php and give the right dbase info see xxxxxxxx
  47.  
  48. 4. Open footer.tpl and put this line in it, you must edit it with your own path:
  49. {php}include('/home/domainname/domains/domainname.com/public_html/3rdparty/onlineusers/online.php');{/php}
  50.  
  51. The reason why i use the footer so you get no conflict with sql Pligg. Hope you can use it. Bye!

URL: http://forums.pligg.com/pligg-mods/13629-online-users-footer-tpl.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.