aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/archive_page.php51
-rw-r--r--views/html/sample_archive.html13
2 files changed, 64 insertions, 0 deletions
diff --git a/src/archive_page.php b/src/archive_page.php
new file mode 100644
index 0000000..bd1f872
--- /dev/null
+++ b/src/archive_page.php
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>PHP answer to the request</title>
+</head>
+<body>
+<p>
+<?php
+ function apply_correct_protocol($url, $protocol) {
+ if (str_contains($url, $protocol)) {
+ return $url;
+ }
+
+ return $protocol . $url;
+ }
+
+ function does_website_exist($url) {
+ $result = false;
+
+ // Check if the site exists with https
+ $https_url = apply_correct_protocol($url, "https://");
+ if ($https_url != $url) {
+ $url_headers = @get_headers($https_url);
+ $result |= $url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found';
+ }
+
+ // Check if the site exists with http
+ $http_url = apply_correct_protocol($url, "http://");
+ if ($http_url != $url) {
+ $url_headers = @get_headers($http_url);
+ $result |= $url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found';
+ }
+
+ // 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);
+ $result |= $url_headers && $url_headers[0] != 'HTTP/1.1 404 Not Found';
+
+ return $result;
+ }
+
+ $WEBSITE_CATEGORY = 'page_url';
+ $website_url = $_POST[$WEBSITE_CATEGORY];
+ $website_exists = does_website_exist($website_url) ? "true" : "false";
+ echo "Website exists: $website_exists";
+?>
+</p>
+</body>
+</html>
diff --git a/views/html/sample_archive.html b/views/html/sample_archive.html
new file mode 100644
index 0000000..ea21c31
--- /dev/null
+++ b/views/html/sample_archive.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="bg">
+<head>
+ <meta charset="UTF-8">
+ <title>Archive a page</title>
+</head>
+<body>
+ <form action="../../src/archive_page.php" method="POST">
+ <input type="text" name="page_url">
+ <input type="submit" name"archive_page_button">
+ </form>
+</body>
+</html>