blob: dc720451e7379b6ecfddecd3be70f5198546f135 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
<?php
function on_get() {
global $page;
try {
$page = Database\Webpage::fromDB($_GET["page_url"]);
$page->incrementVisits();
}
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;
}
|