blob: 9c37fb0c0311b0e978ecf60953c86cbbb8675107 (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<!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';
$DATABASE_NAME = 'db';
$TABLE_NAME = 'users';
$website_url = $_POST[$WEBSITE_CATEGORY];
$website_exists = does_website_exist($website_url) ? "true" : "false";
echo "Website exists: $website_exists" . "<br/>";
try {
$db = new PDO("mysql:host=localhost;dbname=$DATABASE_NAME", $user, $password);
echo $db->query("DESCRIBE $TABLE_NAME");
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
</p>
</body>
</html>
|