active_get.php 1.0 KB

123456789101112131415161718192021222324252627282930
  1. <?php
  2. //统计用户经验值
  3. require_once '../path.php';
  4. require_once "../public/function.php";
  5. $output = array();
  6. if (isset($_GET["userid"])) {
  7. $userid = $_GET["userid"];
  8. } else if (isset($_COOKIE["userid"])) {
  9. $userid = $_COOKIE["userid"];
  10. } else {
  11. exit;
  12. }
  13. if (isset($userid)) {
  14. $dns = "" . _FILE_DB_USER_ACTIVE_;
  15. $dbh = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
  16. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  17. $query = "SELECT date,duration,hit FROM active_index WHERE user_id = ? ";
  18. $sth = $dbh->prepare($query);
  19. $sth->execute(array($userid));
  20. $last = 0;
  21. while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
  22. $curr = $last + $row["duration"] / 3600000;
  23. $output[] = array($row["date"], number_format($last, 3, ".", ""), number_format($curr, 3, ".", ""), number_format($last, 3, ".", ""), number_format($curr, 3, ".", ""), $row["hit"]);
  24. $last = $curr;
  25. }
  26. $json = json_encode($output);
  27. echo str_replace('"', '', $json);
  28. }