12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?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(" ", true, $code);
- /* header("HTTP/ $code $message"); */
- die(json_encode(array("code" => intval($code), "message" => $message)));
- }
-
- function get_param($array, $key, $is_error)
- {
- if (isset($array[$key]))
- return $array[$key];
- else if ($is_error)
- error(400, "Missing parameters");
- else
- return false;
- }
-
- function get_post($key, $is_error = true)
- {
- return get_param($_POST, $key, $is_error);
- }
-
- function get_get($key, $is_error = true)
- {
- return get_param($_GET, $key, $is_error);
- }
-
- function check_float($f, $def = null)
- {
- return is_numeric($f) ? $f : $def;
- }
-
- function check_int($i, $def = null)
- {
- return is_numeric($i) && $i == (int)$i ? $i : $def;
- }
-
- function check_table_field($header, $table, $field)
- {
- $headers = apache_request_headers();
- if (!isset($headers[$header]))
- return false;
- $u = database_exec("SELECT id FROM $table WHERE `$field` = :data",
- array(":data" => $headers[$header]))->fetch();
- if (!$u)
- return false;
- return $headers[$header];
- }
-
- ?>
|