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

utils.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. function starts_with($haystack, $needle)
  3. {
  4. return ($needle === ""
  5. || strrpos($haystack, $needle, -strlen($haystack)) !== false);
  6. }
  7. function ends_with($haystack, $needle)
  8. {
  9. return ($needle === ""
  10. || strpos($haystack, $needle, strlen($haystack) - strlen($needle))
  11. !== false);
  12. }
  13. function error($code, $message)
  14. {
  15. header("HTTP/ $code $message");
  16. die(json_encode(array("code" => intval($code), "message" => $message)));
  17. }
  18. function get_param($array, $key, $is_error)
  19. {
  20. if (isset($array[$key]))
  21. return $array[$key];
  22. else if ($is_error)
  23. error(400, "Missing parameters");
  24. else
  25. return false;
  26. }
  27. function get_post($key, $is_error = true)
  28. {
  29. return get_param($_POST, $key, $is_error);
  30. }
  31. function get_get($key, $is_error = true)
  32. {
  33. return get_param($_GET, $key, $is_error);
  34. }
  35. function check_table_field($header, $table, $field)
  36. {
  37. $headers = apache_request_headers();
  38. if (!isset($headers[$header]))
  39. return false;
  40. $u = database_exec("SELECT id FROM $table WHERE `$field` = :data",
  41. array(":data" => $headers[$header]))->fetch();
  42. if (!$u)
  43. return false;
  44. return $headers[$header];
  45. }
  46. ?>