From d909b2a29ef4050134cacdc4ce5da855cb49e9d0 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 7 Jan 2018 16:40:10 +0100 Subject: [PATCH] Created a function to check posted URLs --- functions/requests.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/functions/requests.php b/functions/requests.php index 9180941..25d3edc 100644 --- a/functions/requests.php +++ b/functions/requests.php @@ -260,6 +260,27 @@ function check_post_file(string $name) : bool { } +/** + * Check the validity of a URL specified in a request + * + * @param string $name The name of the $_POST field containing the URL + * @return bool True if the url is valid / false else + */ +function check_post_url(string $name) : bool { + + //Check if image exists + if(!isset($_POST[$name])) + return false; + $url = $_POST[$name]; + + //Check URL + if(!filter_var($url, FILTER_VALIDATE_URL)) + return false; + + //The URL seems to be valid + return true; +} + /** * Check the validity of a Youtube video ID *