aboutsummaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
authorGeorgi Nikolov <ggeorgi60@gmail.com>2025-01-25 15:23:14 +0200
committerGeorgi Nikolov <ggeorgi60@gmail.com>2025-01-25 15:23:14 +0200
commitdb285a4be28e6da35be65424b2f324dd04e9becf (patch)
tree3b713f2f2e10f39194e39a32f36f6ef855967198 /controllers
parent46e75813c66807fd0297cbf3514a1a5f549d604a (diff)
downloadnowayforward_human-db285a4be28e6da35be65424b2f324dd04e9becf.tar
nowayforward_human-db285a4be28e6da35be65424b2f324dd04e9becf.tar.gz
nowayforward_human-db285a4be28e6da35be65424b2f324dd04e9becf.zip
Handled the search url not existing
Diffstat (limited to 'controllers')
-rw-r--r--controllers/archive.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/controllers/archive.php b/controllers/archive.php
index a54387b..dc72045 100644
--- a/controllers/archive.php
+++ b/controllers/archive.php
@@ -8,3 +8,39 @@ function on_get() {
}
catch(Exception $e) {}
}
+
+function applyCorrectProtocol($url, $protocol) : string {
+ if (str_contains($url, $protocol)) {
+ return $url;
+ }
+ return $protocol . $url;
+}
+
+function doesWebsiteExist($url) : bool {
+ // Check if the site exists with https
+ $https_url = applyCorrectProtocol($url, "https://");
+ if ($https_url != $url) {
+ $url_headers = @get_headers($https_url);
+ if ($url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found') {
+ return true;
+ }
+ }
+
+ // Check if the site exists with http
+ $http_url = applyCorrectProtocol($url, "http://");
+ if ($http_url != $url) {
+ $url_headers = @get_headers($http_url);
+ if ($url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found') {
+ return true;
+ }
+ }
+
+ // Check if the site exists as is
+ // Will take effect when the user has entered the https/http protocol with the site
+ $url_headers = @get_headers($url);
+ if ($url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found') {
+ return true;
+ }
+
+ return false;
+}