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.

utils.php 975B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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_post($key, $is_error = true)
  19. {
  20. if (isset($_POST[$key]))
  21. return $_POST[$key];
  22. else if ($is_error)
  23. error(400, "Missing parameters");
  24. else
  25. return false;
  26. }
  27. function check_table_field($header, $table, $field)
  28. {
  29. $headers = apache_request_headers();
  30. if (!isset($headers[$header]))
  31. return false;
  32. $u = database_exec("SELECT id FROM $table WHERE `$field` = :data",
  33. array(":data" => $headers[$header]))->fetch();
  34. if (!$u)
  35. return false;
  36. return $headers[$header];
  37. }
  38. ?>