Skip to content

Commit ff6fae5

Browse files
Check if URL is valid
1 parent cc70ed2 commit ff6fae5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

index.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ function URL_check(string $url): string {
4848
)
4949
);
5050

51+
// Verify the URL is valid
52+
if (!filter_var($url, FILTER_VALIDATE_URL)) {
53+
return '<span class="glyph-offline" data-bs-toggle="tooltip" data-bs-title="invalid-url"><i class="fas fa-circle-xmark"></i></span>';
54+
}
55+
5156
// Get the headers and 3-digit status code
5257
$headers = get_headers($url);
5358

5459
// If headers are false or the array is empty
55-
if ($headers === false || !isset($headers[0])) {
60+
$headers = @get_headers($url);
61+
if (!$headers || !isset($headers[0])) {
5662
return '<span class="glyph-offline" data-bs-toggle="tooltip" data-bs-title="php-error"><i class="fas fa-circle-xmark"></i></span>';
5763
}
5864

0 commit comments

Comments
 (0)