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