helpers_default.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. if (! function_exists('pre')) {
  3. function pre($var, $exit = false, $prefix = '') {
  4. echo "<pre>";
  5. if (!empty($prefix)) {
  6. echo $prefix;
  7. }
  8. print_r($var);
  9. echo "</pre>";
  10. if ($exit) {
  11. exit;
  12. }
  13. }
  14. }
  15. if (! function_exists('errorHttp')) {
  16. function errorHttp($error_code, $message='An error has occured', $title='Error') {
  17. header("HTTP/1.0 " . $error_code . " " . $title);
  18. echo '<h1>' . $title . '</h1>';
  19. echo '<p>' . $message . '</p>';
  20. exit;
  21. }
  22. }
  23. if (! function_exists('redirect')) {
  24. function redirect($url, $http_code=302) {
  25. header('Location: ' . $url, true, $http_code);
  26. exit;
  27. }
  28. }
  29. if (! function_exists('get')) {
  30. function get($key, $default_value=null) {
  31. return isset($_GET[$key]) ? $_GET[$key] : $default_value;
  32. }
  33. }
  34. if (! function_exists('post')) {
  35. function post($key, $default_value=null) {
  36. return isset($_POST[$key]) ? $_POST[$key] : $default_value;
  37. }
  38. }
  39. if (! function_exists('session')) {
  40. function session($key, $default_value=null) {
  41. return isset($_SESSION[$key]) ? $_SESSION[$key] : $default_value;
  42. }
  43. }
  44. if (! function_exists('cookie')) {
  45. function cookie($key, $default_value=null) {
  46. return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default_value;
  47. }
  48. }