diff options
| -rw-r--r-- | controllers/archive.php | 36 | ||||
| -rw-r--r-- | views/archive/index.php | 6 |
2 files changed, 42 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; +} diff --git a/views/archive/index.php b/views/archive/index.php index 7aba050..d30ddf2 100644 --- a/views/archive/index.php +++ b/views/archive/index.php @@ -23,6 +23,12 @@ </section> <?php endforeach; ?> +<?php elseif(!doesWebsiteExist($_GET["page_url"])): ?> + <h2>"<?php echo $_GET["page_url"] ?>" Does not exist!</h2> + <p>Submit another request or check the spelling of the site and try again</p> + <a href="/home/index.php">Go back!</a> + + <?php else: ?> <h2>"<?php echo $_GET["page_url"] ?>" hasn't been archived yet!</h2> <form action="/sample_archive/index.php" method="POST"> |
