users.php 994 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. function getSetup($key = null) {
  3. $arr = parse_ini_file('setup.ini');
  4. return isset($key) ? $arr[$key] : $arr;
  5. }
  6. session_start();
  7. if (!isset($_SESSION['name'])) return;
  8. $isApc = extension_loaded('apc');
  9. $setup = getSetup();
  10. $time = time();
  11. $date = date('Y-m-d', $time);
  12. $uniqid = uniqid();
  13. $id = $time.'-'.$uniqid;
  14. $name = $_SESSION['name'];
  15. $escaped = preg_replace('/[^A-Za-z0-9_\-]/', '_', $name);
  16. $tmpDir = './tmp/';
  17. $historyDir = './history/';
  18. $tmpFile = $tmpDir.'cache';
  19. $tmpUsers = $tmpDir.'users/';
  20. $historyFile = $historyDir.$date;
  21. $fh = fopen($tmpUsers.$escaped, 'w') or die("Can't create file");
  22. fwrite($fh, "connected");
  23. fclose($fh);
  24. $res = array();
  25. $users = array_diff(scandir($tmpUsers), array('.', '..'));
  26. foreach ( $users as $user )
  27. {
  28. if (time()-filemtime($tmpUsers.$user) > 10) {
  29. // file/user older than 10 sec
  30. unlink($tmpUsers.$user);
  31. } else {
  32. // file younger than 2 hours
  33. array_push($res, $user);
  34. }
  35. }
  36. echo json_encode(array('data' => $res));