Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

utils.php 935B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. return database_exec("SELECT id FROM $table WHERE `$field` = :data",
  33. array(":data" => $headers[$header]))-> fetch()
  34. !== false;
  35. }
  36. ?>