kp.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. ini_set('display_errors', true);
  3. ini_set("include_path", '/home/stevenos/php:' . ini_get("include_path"));
  4. error_reporting(E_ALL);
  5. date_default_timezone_set('Asia/Shanghai');
  6. global $user_online;
  7. function load_data()
  8. {
  9. global $user_online;
  10. $data = file_get_contents($user_online);
  11. $data = json_decode($data, true);
  12. $json = array();
  13. if (sizeof($data) > 0) {
  14. foreach ((array) $data as $single_data) {
  15. if (date('mdHis') - date('mdHis', strtotime(date('Y-') . $single_data["time"])) < 60) {
  16. if (strpos(json_encode($json), $single_data['ip'])) {
  17. continue;
  18. }
  19. $json[] = array(
  20. "ip" => $single_data["ip"],
  21. "ua" => $single_data["ua"],
  22. "time" => $single_data["time"]
  23. );
  24. }
  25. }
  26. }
  27. $data = array_unique($json, SORT_REGULAR);
  28. return $data;
  29. }
  30. function save_data($data)
  31. {
  32. global $user_online;
  33. $old_data = load_data();
  34. if (!strpos(json_encode($old_data), $data['ip'])) {
  35. array_push($old_data, $data);
  36. $old_data = array_unique($old_data, SORT_REGULAR);
  37. }
  38. file_put_contents($user_online, json_encode($old_data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
  39. }
  40. preg_match('/(\d+)\-.*/', $_GET['g'], $matches);
  41. $user_online = $matches[1];
  42. $user_online = $user_online . ".txt";
  43. if ($user_online == '.txt') {
  44. exit();
  45. }
  46. $action = isset($_GET['action']) ? $_GET['action'] : 's';
  47. if ($action == "s") {
  48. $json = array(
  49. "ip" => getenv('REMOTE_ADDR'),
  50. "ua" => getenv('HTTP_USER_AGENT'),
  51. "time" => date('m-d H:i:s')
  52. );
  53. if (file_exists($user_online)) {
  54. save_data($json);
  55. } else {
  56. file_put_contents($user_online, '[]');
  57. save_data($json);
  58. }
  59. header('Content-Type: image/png');
  60. @ob_end_clean();
  61. @readfile('pyqbot.png');
  62. @flush();
  63. @ob_flush();
  64. exit();
  65. } elseif ($action == "p") {
  66. echo json_encode(load_data());
  67. exit();
  68. } else {
  69. exit("error!");
  70. }