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 *