-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.php
103 lines (89 loc) · 3.05 KB
/
home.php
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
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
include 'db_conn_web.php';
function getPassword($connection) { //현재 비밀번호 가져오기 및 표시
$pwsql = "SELECT pw FROM password ORDER BY date DESC LIMIT 1";
$stmt = $connection->query($pwsql);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result['pw'];
}
if (isset($_SESSION['id']) && isset($_SESSION['user_name'])) {
if (isset($_POST['P_RESET'])) {
// 4자리 숫자 비밀번호 생성
$password = strval(rand(1000, 9999));
// 비밀번호와 시간을 데이터베이스에 입력
$insertSql = "INSERT INTO password (pw) VALUES (:pw)";
$insertStmt = $connection->prepare($insertSql);
$insertStmt->bindParam(':pw', $password);
$insertStmt->execute();
$password = getPassword($connection);
} else if (isset($_POST['LOCK_ON'])) {
// errorcode 컬럼에 0 삽입(비밀번호 비교활성화)
$errorCode = 0;
$insertSql = "INSERT INTO error (errorcode) VALUES (:errorcode)";
$insertStmt = $connection->prepare($insertSql);
$insertStmt->bindParam(':errorcode', $errorCode);
$insertStmt->execute();
echo "<script>alert('비밀번호 입력이 활성화되었습니다.');</script>";
}
$password = getPassword($connection);
$dataSql = "SELECT word, date FROM textms ORDER BY date DESC LIMIT 10";
$dataStmt = $connection->query($dataSql);
$dataResults = $dataStmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
<title>HOME</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" type="text/css" href="style.css">
<script>
function redirectToPage(data) {
window.location.href = data+".php";
}
</script>
</head>
<body>
<form method="POST">
<h2>현재 비밀번호 : <?php echo $password; ?></h2>
<p> -------------------------------------------------------- </p>
<p style="font-size:20px"><strong>작동 내역</strong></p>
<table>
<?php foreach ($dataResults as $row): ?>
<tr>
<td><?php echo date('m.d H:i:s', strtotime($row['date'])); ?></td>
<?php if ($row['word'] === "사진을 촬영했습니다."
|| $row['word'] === "비밀번호가 비활성화 되었습니다."): ?>
<td style="color: red;"><?php echo $row['word']; ?></td>
<?php else: ?>
<td><?php echo $row['word']; ?></td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</table>
<br>
<style>
.button-container {
display: flex;
justify-content: center;
}
.button-container button {
width: 300px;
padding: 10px;
height: 38px;
}
</style>
<div class="button-container">
<button type="submit" name="P_RESET">비밀번호 변경</button>
<button type="submit" name="LOCK_ON">잠금 해제</button>
<button type="button" onclick="redirectToPage('image')">침입자 확인</button><br><br><br>
</div>
<a href="logout.php">로그아웃</a>
</form>
</body>
</html>
<?php
}else {
header("Location: index.php");
exit();
}
?>