-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaccount.php
More file actions
135 lines (126 loc) · 4.11 KB
/
account.php
File metadata and controls
135 lines (126 loc) · 4.11 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
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
<?php
session_start();
require('connect.php');
if ($_SESSION['username']) {
?>
<html>
<head>
<title>Trang chủ</title>
</head>
<body>
<center><h1> Tài khoản </h1></center>
<?php include("header.php");
$query = "SELECT * FROM users WHERE username='".$_SESSION['username']."'";
$results = mysqli_query($db, $query);
$rows= mysqli_num_rows($results);
while($row = mysqli_fetch_assoc($results)){
$id= $row["id"];
$username=$row["username"];
$email= $row["email"];
$score= $row["score"];
$topics= $row["topics"];
$date= $row["date"];
$replies=$row["replies"];
$prof_pic=$row["profile_pic"];
}
?>
<center><?php echo "<img src='$prof_pic' width ='70' height='70' >";?><br/>
Tài khoản: <?php echo $username ?> <br/>
ID: <?php echo $id ?> <br/>
Email: <?php echo $email ?> <br/>
Ngày tham gia: <?php echo $date ?> <br/>
Số câu trả lời: <?php echo $replies ?> <br/>
Score: <?php echo $score ?> <br/>
Bài viết: <?php echo $topics ?> <br/>
<a href='account.php?action=cp'>Thay đổi mật khẩu </a><br/>
<a href='account.php?action=ci'>Thay đổi ảnh đại diện </a></center>
</body>
</html>
<?php
if(@$_GET['action']=="logout")
{
session_destroy();
unset($_SESSION['username']);
header("location: login.php");
}
if(@$_GET['action']=="ci"){
echo "<form action='account.php?action=ci' method='POST' enctype='multipart/form-data' ><center>
<br/>
Chỉ có thể tải được ảnh dạng <b> .PNG .JPG .JPEG </b><br/>
<input type ='file' name ='image'><br/>
<input type ='submit' name ='change_pic' value='change'><br/>
";
if(isset($_POST['change_pic'])){
$errors=array();
$allowed_e=array('png','jpg','jpeg');
$file_name=$_FILES['image']['name'];
$file_e=strtolower(pathinfo($file_name,PATHINFO_EXTENSION));
$file_s= $_FILES['image']['size'];
$file_tmp=$_FILES['image']['tmp_name'];
if(in_array($file_e, $allowed_e)==false){
$errors[]='Phần mở rộng của file không hợp lệ';
}
if($file_s>2097152){
$errors[]='File này nặng vl (>2mb)';
}
if(empty($errors)){
move_uploaded_file($file_tmp,'images/'.$file_name);
$image_up='images/'.$file_name;
$query = "SELECT * FROM users WHERE username='".$_SESSION['username']."'";
$results = mysqli_query($db, $query);
$rows= mysqli_num_rows($results);
while($row = mysqli_fetch_assoc($results)){
$db_image=$row['profile_pic'];
}
$upd = "UPDATE users SET profile_pic='".$image_up." 'WHERE username='".$_SESSION['username']."'";
$check = mysqli_query($db, $upd);
echo "Đổi ảnh đại diện thành cmn công";
}else{
foreach($errors as $error){
echo $error,'<br/>';
}
}
}
echo "</form></center>";
}
if(@$_GET['action']=="cp"){
echo "<form action='account.php?action=cp' method='POST'><center>";
echo "
Mật khẩu cũ: <input type='password' name='pass' ><br/>
Mật khẩu mới: <input type='password' name='newpass'><br/>
Nhập lại mật khẩu: <input type='password' name='repass'><br/>
<button type='submit' name='change_pass' value='change' >Đổi mật khẩu</button>
";
if(isset($_POST['change_pass'])){
$pass = mysqli_real_escape_string($db, $_POST['pass']);
$newpass = mysqli_real_escape_string($db, $_POST['newpass']);
$repass = mysqli_real_escape_string($db, $_POST['repass']);
$query = "SELECT * FROM users WHERE username='".$_SESSION['username']."'";
$results = mysqli_query($db, $query);
$rows= mysqli_num_rows($results);
while($row = mysqli_fetch_assoc($results)){
$get_pass=$row['password'];
}
if($get_pass==sha1($pass)){
if(strlen($newpass)>=5){
if($newpass==$repass){
$upd = "UPDATE users SET password='".sha1($newpass)."' WHERE username='".$_SESSION['username']."'";
$check = mysqli_query($db, $upd);
echo "fuck";
}else{
echo "Mật khẩu nhập lại không khớp";
}
}else{
echo "Mật khẩu cần dài hơn 6 kí tự ";
}
}else{
echo "Mật khẩu hiện tại không đúng";
}
}
echo "</center></form>";
}
}else {
echo " bạn cần đăng nhập ";
header('location: login.php');
}
?>