You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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(" ", true, $code);
  16. /* header("HTTP/ $code $message"); */
  17. die(json_encode(array("code" => intval($code), "message" => $message)));
  18. }
  19. function get_param($array, $key, $is_error)
  20. {
  21. if (isset($array[$key]))
  22. return $array[$key];
  23. else if ($is_error)
  24. error(400, "Missing parameters");
  25. else
  26. return false;
  27. }
  28. function get_post($key, $is_error = true)
  29. {
  30. return get_param($_POST, $key, $is_error);
  31. }
  32. function get_get($key, $is_error = true)
  33. {
  34. return get_param($_GET, $key, $is_error);
  35. }
  36. function check_float($f, $def = null)
  37. {
  38. return is_numeric($f) ? $f : $def;
  39. }
  40. function check_int($i, $def = null)
  41. {
  42. return is_numeric($i) && $i == (int)$i ? $i : $def;
  43. }
  44. function check_table_field($header, $table, $field)
  45. {
  46. $headers = apache_request_headers();
  47. if (!isset($headers[$header]))
  48. return false;
  49. $u = database_exec("SELECT id FROM $table WHERE `$field` = :data",
  50. array(":data" => $headers[$header]))->fetch();
  51. if (!$u)
  52. return false;
  53. return $headers[$header];
  54. }
  55. ?>