-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
90 lines (83 loc) · 2.82 KB
/
Copy pathinstall.php
File metadata and controls
90 lines (83 loc) · 2.82 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
session_start();
require 'lib/common.php';
require 'lib/install.php';
$password = '';
// Checking if the form was submitted
if ($_POST) {
$pdo = connectDatabase();
list($rowCounts, $error) = installDatabase($pdo);
if (!$error) {
$username = 'admin';
list($password, $error) = createUser($pdo, $username);
}
$_SESSION['count'] = $rowCounts;
$_SESSION['error'] = $error;
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['try-install'] = true;
redirectAndExit('install.php');
}
// Checking if just installed and display results or errors
$attempted = false;
if (isset($_SESSION['try-install'])) {
$attempted = true;
$count = $_SESSION['count'] ?? [];
$error = $_SESSION['error'] ?? '';
$username = $_SESSION['username'] ?? '';
$password = $_SESSION['password'] ?? '';
//Unset session variables
unset($_SESSION['count']);
unset($_SESSION['error']);
unset($_SESSION['username']);
unset($_SESSION['password']);
unset($_SESSION['try-install']);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blog Installer</title>
<style>
.box {
border: 1px dotted silver;
border-radius: 5px;
padding: 10px;
margin: 10px 0;
}
.error { background-color: #ff6666; }
.success { background-color: #88ff88; }
</style>
</head>
<body>
<?php if ($attempted): ?>
<?php if ($error): ?>
<div class="error box">
<?php echo htmlspecialchars($error, ENT_QUOTES, 'UTF-8'); ?>
</div>
<?php else: ?>
<div class="success box">
<p>The database and demo data were created successfully.</p>
<?php foreach ($count as $tableName => $rowCount): ?>
<p><?php echo htmlspecialchars($rowCount, ENT_QUOTES, 'UTF-8'); ?> new
<?php echo htmlspecialchars($tableName, ENT_QUOTES, 'UTF-8'); ?>s were created.</p>
<?php endforeach; ?>
<p>The new '<?php echo htmlspecialchars($username, ENT_QUOTES, 'UTF-8'); ?>' password is
<span style="font-size: 1.2em;"><?php echo htmlspecialchars($password, ENT_QUOTES, 'UTF-8'); ?></span>
(copy it to clipboard if you wish).</p>
</div>
<p>
<a href="index.php">VIEW THE BLOG</a><br>
<a href="install.php">INSTALL AGAIN</a>
</p>
<?php endif; ?>
<?php else: ?>
<p>Click the install button to reset the database.</p>
<form method="post">
<input name="install" type="submit" value="Install" />
</form>
<?php endif; ?>
</body>
</html>