diff options
author | Freya Murphy <freya@freyacat.org> | 2024-03-30 12:14:42 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-03-30 12:14:42 -0400 |
commit | 1f04b83be337cc91a3fabcf4e574e2306f3d2eaa (patch) | |
tree | 74d7d65a7047e60d1877384e3c7b0d70c7b0e49a /web/_model/request.php | |
parent | start database (user and post), and initial barebones home page (diff) | |
download | xssbook2-1f04b83be337cc91a3fabcf4e574e2306f3d2eaa.tar.gz xssbook2-1f04b83be337cc91a3fabcf4e574e2306f3d2eaa.tar.bz2 xssbook2-1f04b83be337cc91a3fabcf4e574e2306f3d2eaa.zip |
refactor
Diffstat (limited to 'web/_model/request.php')
-rw-r--r-- | web/_model/request.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/web/_model/request.php b/web/_model/request.php new file mode 100644 index 0000000..4cce07a --- /dev/null +++ b/web/_model/request.php @@ -0,0 +1,40 @@ +<?php /* Copyright (c) 2024 Freya Murphy */ +class Request_model extends Model { + + function __construct($load) { + parent::__construct($load); + } + + /** + * Loads a string from the GET request + * @param string $key - the name for the query param + * @param string $default - the default value if not exists + */ + public function get_str($key, $default = NULL): string | NULL { + if (!array_key_exists($key, $_GET)) { + return $default; + } else { + return $_GET[$key]; + } + } + + /** + * Loads a number from the GET request + * @param string $key - the name for the query param + * @param int $default - the default value if not exists + */ + public function get_int($key, $default = NULL): int | NULL { + if (!array_key_exists($key, $_GET)) { + return $default; + } else { + $val = $_GET[$key]; + $val = intval($val); + if ($val < 0) { + return 0; + } else { + return $val; + } + } + } + +} |