diff options
author | Freya Murphy <freya@freyacat.org> | 2024-12-11 22:05:51 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-12-11 22:05:51 -0500 |
commit | ce123807279506d10f79fdf7214b1ea12b654648 (patch) | |
tree | 29fff07f47e8e548af3db219621121aa2715347f /src/web/core/controller.php | |
parent | update error lang (diff) | |
download | website-ce123807279506d10f79fdf7214b1ea12b654648.tar.gz website-ce123807279506d10f79fdf7214b1ea12b654648.tar.bz2 website-ce123807279506d10f79fdf7214b1ea12b654648.zip |
switch to POST for posting comments
Diffstat (limited to '')
-rw-r--r-- | src/web/core/controller.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/web/core/controller.php b/src/web/core/controller.php index ac1e458..ca892e2 100644 --- a/src/web/core/controller.php +++ b/src/web/core/controller.php @@ -39,4 +39,27 @@ abstract class Controller extends Component { die(); } + /** + * Returns HTTP POST information if POST request. + * Returns 405 Method Not Allowed if not. + * + * If $key is specified, returns only that key. otherwise + * returns HTTP 400 Bad Request; + */ + protected function post_data(?string $key = NULL): array|string + { + // only post requests allowed + if ($_SERVER['REQUEST_METHOD'] != 'POST') + $this->error(405); + + // return entire $_POST array + if (!$key) + return $_POST; + + if (!isset($_POST[$key])) + $this->error(400); + + return $_POST[$key]; + } + } |