-
Notifications
You must be signed in to change notification settings - Fork 0
/
avatar.php
139 lines (124 loc) · 3.39 KB
/
avatar.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php include "dbLogic.php";
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// if the user tries to modify others avatar then redirect to index.php
if (isset($_REQUEST['uid'])) {
$id = (int)$_REQUEST['uid'];
if ($id != $_SESSION['uid']) {
header("Location: index.php");
exit;
}
}
if (isset($_POST['avatar'])) {
$_SESSION['avatar'] = $_POST['avatar'];
// Update the avatar in the userdetails table
$uid = $_SESSION['uid'];
$avatar = $_POST['avatar'];
$sql = $conn->prepare("UPDATE userdetails SET avatar = ? WHERE user_id = ?");
$path = 'avatar/' . $avatar;
$sql->bind_param('si', $path, $uid);
$sql->execute();
$sql->close();
if (isset($_SESSION['avatar'])) {
header("Location: /BlogsConn/index.php");
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Select Avatar</title>
</head>
<style>
.avatar-list label {
display: inline-block;
cursor: pointer;
margin-right: 10px;
}
.avatar-list label:hover img {
border: 2px solid #ccc;
}
.avatar-list input[type="radio"] {
display: none;
}
.avatar-list img {
width: 100px;
height: 100px;
border-radius: 50%;
border: 2px solid transparent;
transition: border-color 0.3s ease;
}
.avatar-display {
margin-top: 20px;
text-align: center;
}
.avatar-icon img {
width: 150px;
height: 150px;
border-radius: 50%;
border: 2px solid #ccc;
}#select-btn{
margin-top: 20px;
padding: 10px 20px;
border: none;
border-radius: 5px;
background: #77619e;
color: #fff;
font-size: 18px;
cursor: pointer;
transition: all 0.3s ease;
}
</style>
<body>
<div class="container">
<div class="avatar-selection">
<h1>Select Your Avatar</h1>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<div class="avatar-list">
<label>
<input type="radio" name="avatar" value="avatar1.png">
<img src="avatar/avatar1.png" alt="Avatar 1">
</label>
<label>
<input type="radio" name="avatar" value="avatar2.png">
<img src="avatar/avatar2.png" alt="Avatar 2">
</label>
<label>
<input type="radio" name="avatar" value="avatar3.png">
<img src="avatar/avatar3.png" alt="Avatar 3">
</label>
<label>
<input type="radio" name="avatar" value="avatar4.png">
<img src="avatar/avatar4.png" alt="Avatar 4">
</label>
<label>
<input type="radio" name="avatar" value="avatar5.png">
<img src="avatar/avatar5.png" alt="Avatar 5">
</label>
<label>
<input type="radio" name="avatar" value="avatar6.png">
<img src="avatar/avatar6.png" alt="Avatar 6">
</label>
</div>
<button class="btn" type="submit" id="select-btn">Select</button>
</form>
</div>
<div class="avatar-display">
<div class="avatar-icon">
<?php if(isset($_SESSION['avatar'])) {
$avatar = $_SESSION['avatar'];
$avatar_array = array("avatar1.png", "avatar2.png", "avatar3.png", "avatar4.png", "avatar5.png", "avatar6.png");
if(!in_array($avatar, $avatar_array)) {
$_SESSION['avatar'] = "avatar.png";
}
?>
<?php } else { ?>
<img src="avatar/avatar.png" alt="Default Avatar">
<?php } ?>
</div>
</div>
</div>
<script type="text/javascript" src="static/js/avatar.js"></script>
</body>
</html>