Advertisement
Coders_Cavern

Users online meter (PHP)

Apr 10th, 2016
18,026
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. Users online meter
  2. <?php
  3. if (!is_dir('OU')) mkdir('OU');
  4. if (!is_dir('OG')) mkdir('OG');
  5. if (isset($_POST['logout'])) setcookie('user',$_GET['user'],time()-1000);
  6. $files = scandir('OU');
  7. foreach ($files as $user){
  8. if ($user=='.' || $user=='..') continue;
  9. $handle=fopen("OU/$user",'r');
  10. $time = fread($handle, filesize("OU/$user"));
  11. fclose($handle);
  12. if ((time()-$time)>6) unlink("OU/$user");
  13. }
  14. $gcount=0;
  15. $files = scandir('OG');
  16. foreach ($files as $user){
  17. if ($user=='.' || $user=='..') continue;
  18. $handle=fopen("OG/$user",'r');
  19. $time = fread($handle, filesize("OG/$user"));
  20. fclose($handle);
  21. if ((time()-$time)>6) {unlink("OG/$user");$gcount--;}
  22. $gcount++;
  23. }
  24.  
  25. if (!is_file('check.php')){
  26. $handle = fopen("check.php", "w");
  27. $c='<meta http-equiv="refresh" content="3">
  28. <?php
  29. if (isset($_GET["user"]) && isset($_GET["type"])){
  30. $user=$_GET["user"];
  31. $type=$_GET["type"];
  32. if ($type=="user"){
  33. $handle = fopen("OU/$user", "w");
  34. fwrite($handle, time());
  35. fclose($handle);
  36. }else{
  37. $handle = fopen("OG/$user", "w");
  38. fwrite($handle, time());
  39. fclose($handle);
  40. }
  41. }
  42. ?>';
  43. fwrite($handle, $c);
  44. fclose($handle);
  45. }
  46.  
  47. if (isset($_POST['submit'])){
  48. if ($_POST['user']!=''){
  49. setcookie('user',$user,time()+1000);
  50. $user=$_POST['user'];
  51. $handle = fopen("OU/$user", "w");
  52. fwrite($handle, time());
  53. fclose($handle);
  54. $type='user';
  55. }}else{
  56. if (isset($_COOKIE['me']))
  57. $user=$_COOKIE['me'];
  58. else{
  59. $gcount++;
  60. $user='Guest'.(rand(1,999)*rand(1,999)/rand(1,999));
  61. setcookie('me',$user);}
  62. $handle = fopen("OG/$user", "w");
  63. fwrite($handle, time());
  64. fclose($handle);
  65. $type='guest';
  66. }
  67.  
  68. $files = scandir('OU');
  69. $users='';
  70. foreach ($files as $userd) if ($userd!='.' && $userd!='..') $users.='and '.$userd."<br>";
  71. ?>
  72. <table style="border: 1px solid #000000; width: 343px; background-color: #F8F8D7;" align="center">
  73. <?php if (!isset($_POST['submit'])&& !isset($_COOKIE['user'])){ ?>
  74. <form action="" method="post">
  75. <tr>
  76. <td style="padding:5px;width: 105px; font-family: 'Times New Roman', Times, serif; font-size: 14pt; border-left-style: solid; border-left-width: 0; border-top-style: solid; border-top-width: 0; border-right-width: 0; border-bottom-width: 0;">User Name:</td>
  77. <td style="padding:5px;border-right-style: solid; border-right-width: 0; border-top-style: solid; border-top-width: 0; width: 123px; border-left-width: 0; border-bottom-width: 0;">
  78. <input name="user" style="width: 220px; font-size: 14pt; font-family: 'Times New Roman', Times, serif;"></td>
  79. </tr>
  80. <tr>
  81. <td style="padding:5px;width: 105px; font-family: 'Times New Roman', Times, serif; font-size: 14pt; border-left-style: solid; border-left-width: 0; border-right-width: 0; border-top-width: 0; border-bottom-width: 0;">Password:</td>
  82. <td style="padding:5px;border-right-style: solid; border-right-width: 0; border-bottom-style: solid; border-bottom-width: 0; width: 123px; border-left-width: 0; border-top-width: 0;">
  83. <input name="pass" style="width: 170px;width: 220px; font-size: 14pt;" type="password"></td>
  84. </tr>
  85. <tr>
  86. <td style="padding:5px; font-family: 'Times New Roman', Times, serif; font-size: 14pt; text-align: right; border-left-style: solid; border-left-width: 0; border-right-style: solid; border-right-width: 0; border-bottom-style: solid; border-bottom-width: 0; border-top-width: 0;" colspan="2">
  87. <br>
  88. <input name="submit" style="font-size: 14pt; font-family: 'times New Roman', Times, serif; color: #F132A8; width: 80px;" type="submit" value="Login"></td>
  89. </tr>
  90. </form>
  91. <?php }else { ?>
  92. <form action="<?php echo $_SERVER['PHP_SELF'].'?user=$user' ?>" method="post">
  93. <td style="padding:5px; font-family: 'Times New Roman', Times, serif; font-size: 14pt; text-align: right; border-left-style: solid; border-left-width: 0; border-right-style: solid; border-right-width: 0; border-bottom-style: solid; border-bottom-width: 0; border-top-width: 0;" colspan="2">
  94. <br>
  95. <input name="logout" style="font-size: 14pt; font-family: 'times New Roman', Times, serif; color: #F132A8; width: 80px;" type="submit" value="Logout"></td>
  96. </form>
  97. <?php } ?>
  98. </table>
  99. <table style="border: 1px solid #000000; width: 343px; background-color: #D7F6F8;" align="center">
  100. <tr>
  101. <td style="padding:5px;font-family: 'Times New Roman', Times, serif; font-size: 14pt; border-left-style: solid; border-left-width: 0; border-top-style: solid; border-top-width: 0; text-align: center; border-right-width: 0; border-bottom-width: 0;">
  102. Who is Online?</td>
  103. </tr>
  104. <tr>
  105. <td style="padding:5px;font-family: 'Times New Roman', Times, serif; font-size: 14pt; border-left-style: solid; border-left-width: 0; text-align: center; border-right-width: 0; border-top-width: 0; border-bottom-width: 0;">
  106. <span style="color: #7B0909">
  107. <?php
  108. echo "$gcount Guests<br>";
  109. echo($users);
  110. ?>
  111. </span>
  112. </tr>
  113. </table>
  114. <div style="text-align: center"><br>
  115. <font face="Tahoma"><a target="_blank" href=">
  116. <span style="font-size: 8pt; text-decoration: none"></span></a></font>
  117. </div>
  118.  
  119. <iframe id="I1" border="1" frameborder="1" name="I1" style="visibility:hidden;display:none" src="<?php echo "check.php?user=$user&type=$type" ?>" >Your browser does not support inline frames or is currently configured not to display inline frames.
  120. </iframe>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement