1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- function starts_with($haystack, $needle)
- {
- return ($needle === ""
- || strrpos($haystack, $needle, -strlen($haystack)) !== false);
- }
-
- function ends_with($haystack, $needle)
- {
- return ($needle === ""
- || strpos($haystack, $needle, strlen($haystack) - strlen($needle))
- !== false);
- }
-
- function error($code, $message)
- {
- header("HTTP/ $code $message");
- die(json_encode(array("code" => intval($code), "message" => $message)));
- }
-
- function get_post($key, $is_error = true)
- {
- if (isset($_POST[$key]))
- return $_POST[$key];
- else if ($is_error)
- error(400, "Missing parameters");
- else
- return false;
- }
-
- function check_table_field($header, $table, $field)
- {
- $headers = apache_request_headers();
- if (!isset($headers[$header]))
- return false;
- return database_exec("SELECT id FROM $table WHERE `$field` = :data",
- array(":data" => $headers[$header]))-> fetch()
- !== false;
- }
-
- ?>
|