您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

index.php 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. require_once "utils.php";
  3. require_once "status.php";
  4. require_once "user.php";
  5. require_once "sql.php";
  6. function check_api_key_()
  7. {
  8. $headers = apache_request_headers();
  9. if (!isset($headers["Api-Key"]))
  10. return false;
  11. return database_exec("SELECT id FROM api_keys WHERE `key` = :key",
  12. array(":key" => $headers["Api-Key"]))-> fetch()
  13. !== false;
  14. }
  15. function check_api_key()
  16. {
  17. if (!check_api_key_())
  18. error(401, "Bad API key");
  19. }
  20. function main()
  21. {
  22. $m_get = ($_SERVER['REQUEST_METHOD'] == "GET");
  23. $m_post = ($_SERVER['REQUEST_METHOD'] == "POST");
  24. $matches = array();
  25. $path = rtrim($_GET['_url'], "/");
  26. if ($path === "")
  27. $path = "/";
  28. if (preg_match($path, "^/status/([0-9]+)/confirm$", $matches) && $m_post)
  29. status_confirm($matches[1]);
  30. else if ($path === "/status" && $m_post)
  31. status_create();
  32. else if ($path === "/status/feed" && $m_get)
  33. status_feed();
  34. else if ($path === "/user" && $m_post)
  35. user_create();
  36. else if ($path === "/user/login" && $m_post)
  37. user_login();
  38. else
  39. error(501, "Not implemented");
  40. }
  41. check_api_key();
  42. main();
  43. ?>