document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2.  *Create a file on the dabr root folder (eg: count.php):
  3.  */
  4.  
  5.  
  6. <?php
  7. error_reporting(E_ERROR | E_PARSE);
  8.  
  9. $dataFile = "onlineusers.txt";
  10. if (user_is_authenticated()) {
  11.     $user = user_current_username();
  12. }
  13.  
  14. // this is the time in **minutes** to consider someone online before removing them from our file
  15. // berapa menit tenggang waktu yg dibutuhkan untuk tahu user masih online atau tidak.
  16. $sessionTime = 5;
  17.  
  18. if(!file_exists($dataFile)) {
  19.     $fp = fopen($dataFile, "w+");
  20.     fclose($fp);
  21. }
  22.  
  23. $users = array();
  24. $onusers = array();
  25.  
  26. // check up
  27. $fp = fopen($dataFile, "r");
  28. flock($fp, LOCK_SH);
  29. while(!feof($fp)) {
  30.     $users[] = rtrim(fgets($fp, 32));
  31. }
  32. flock($fp, LOCK_UN);
  33. fclose($fp);
  34.  
  35.  
  36. // clean up
  37. $x = 0;
  38. $alreadyIn = FALSE;
  39. foreach($users as $key => $data) {
  40.     list(,$lastvisit) = explode("|", $data);
  41.     if(time() - $lastvisit >= $sessionTime * 60) {
  42.         $users[$x] = "";
  43.     } else {
  44.         if(strpos($data, $user) !== FALSE) {
  45.             $alreadyIn = TRUE;
  46.             $users[$x] = "$user|" . time(); //updating
  47.         }
  48.     }
  49.     $x++;
  50. }
  51.  
  52. if($alreadyIn == FALSE) {
  53.     $users[] = "$user|" . time();
  54. }
  55.  
  56. // write up
  57. $fp = fopen($dataFile, "w+");
  58. flock($fp, LOCK_EX);
  59. $i = 0;
  60. foreach($users as $single) {
  61.     if($single != "") {
  62.         fwrite($fp, $single . "\\r\\n");
  63.         $i++;
  64.     }
  65. }
  66. flock($fp, LOCK_UN);
  67. fclose($fp);
  68.  
  69. ?>
  70.  
  71. //Create another file (eg: online.php). This file is to show the list of the online users.
  72.  
  73. <?php
  74.  
  75. $myFile = "onlineusers.txt";
  76. $fsc = file($myFile);
  77. $lines = count(file($myFile));
  78.  
  79. $content = "<div>".$lines." Online Users:<br />";
  80. foreach($fsc as $line) {
  81.     $array = explode("|", $line);
  82.     $content .= "<a href=\\"user/".$array[0]."\\">".$array[0]."</a><br/>";
  83. }
  84. $content .= "</div>";
  85.  
  86. ?>
  87.  
  88. //We have to include the count.php file to all the accessible pages.
  89. //In dabr, usually common/theme.php -> function theme_page()
  90.  
  91. ....
  92. if (user_is_authenticated()) {
  93.         require_once("count.php");
  94.     }
  95. echo    \'</body>
  96.         </html>\';
  97.     exit();
  98. And edit the index.php file to add this line
  99. <?php
  100.  
  101. menu_register(array (
  102.     ......
  103.     \'online\' => array (
  104.         \'security\' => true,
  105.         \'callback\' => \'online_page\',
  106.     ),
  107.     ....
  108. ));
  109.  
  110. ?>
  111. //Still at the index.php file just before the browser_detect(); add this line:
  112. <?php
  113.  
  114. function online_page() {
  115.     require_once("online.php");
  116.     theme(\'page\', \'Online Users\', $content);
  117. }
  118.  
  119. ?>
  120. //And don\'t forget to chmod 777 the file onlineusers.txt...
  121.  
  122. //http://dev.writelonger.com/onlineuser.html
');