-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.php
More file actions
208 lines (165 loc) · 5.51 KB
/
profile.php
File metadata and controls
208 lines (165 loc) · 5.51 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1254" />
</head>
<body>
<?php
session_start();
if (isset($_SESSION['userId'])) {
$userId = $_SESSION['userId'];
} else {
header("Location: http://sorubank.ege.edu.tr/~b051164/dersler/lwp/proje/login.php");
die();
}
include "baglan.php";
if($_POST['action'] == "showProfile") {
$q = $_POST['q'];
$result = mysql_query("SELECT * FROM USER
WHERE Id = $q");
while($row = mysql_fetch_array($result)) {
$userId = $row['Id'];
$firstname = $row['FirstName'];
$lastname = $row['LastName'];
$email = $row['Email'];
$password = $row['Password'];
$birthday = $row['Birthday'];
$gender = $row['Gender'];
$picture = $row['PictureURL'];
echo "<p><img src='" . $row['PictureURL'] . "' width='60px'>";
}
mysql_close();
} else {
@include_once "koruma.php";
if ((isset($_POST)) && (isset($_POST['submit']))) {
$submit = secure_var($_POST["submit"]);
} else {
$submit = false;
}
if ($submit) {
$error = array();
$firstName = test_input($_POST["firstName"]);
$lastName = test_input($_POST["lastName"]);
$email = test_input($_POST["email"]);
$password = test_input($_POST["password"]);
$birthday = test_input($_POST["birthday"]);
$gender = test_input($_POST["gender"]);
$pictureURL = ($_POST["pictureURL"]);
if (empty($firstName)) {
$error['firstName'] = "<br>Please enter your name";
} else {
if (!preg_match("/^[a-zA-Z ]*$/", $firstName)) {
$error['firstName'] = "<br>Only letters and white space allowed";
}
}
if (empty($lastName)) {
$error['lastName'] = "<br>Please enter your last name";
} else {
if (!preg_match("/^[a-zA-Z ]*$/", $lastName)) {
$error['lastName'] = "<br>Only letters and white space allowed";
}
}
if (empty($password)) {
$error['password'] = "<br>You must choose a password";
} else {
if (!preg_match("/^\S*(?=\S{6,})\S*$/D", $password)) {
$error['password'] = "<br>Your password length must be 6 at least";
}
}
if (empty($birthday)) {
$error['birthday'] = "<br>Birthday is required";
}
if (empty($gender)) {
$error['gender'] = "<br>Gender is required";
}
if ($_FILES["file"]["name"] != "") {
$allowedExts = array("jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 1000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
$error['pictureURL'] = "<br>Invalid file";
}
else
{
if (file_exists("img/profile/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
$new_filename = $userId . "_" . $firstName . "_" . $lastName ;
$full_local_path = 'img/profile/' . $new_filename . "." . $extension ;
$pictureURL = "http://sorubank.ege.edu.tr/~b051164/dersler/lwp/proje/" . $full_local_path;
move_uploaded_file($_FILES["file"]["tmp_name"], $full_local_path);
}
}
}
else
{
$error['pictureURL'] = "<br>Invalid file";
}
}
if (count($error) == 0) {
mysql_query("UPDATE USER SET FirstName = '$firstName', LastName = '$lastName', Password = '$password',
Birthday = '$birthday', Gender = '$gender', PictureURL = '$pictureURL'
WHERE Id = $userId ");
echo "<br>Your account information has been updated successfully<br><br>";
mysql_close();
header("Location: http://sorubank.ege.edu.tr/~b051164/dersler/lwp/proje/main.php?showProfile=$userId");
die();
}
}
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<form class="form" id="profile_form" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" enctype="multipart/form-data">
First Name:
<input type="text" name="firstName" value="<?php echo $firstname; ?>">
<span class="error">* <?php echo $error['firstName'];?> </span>
<br><br>
Last Name:
<input type="text" name="lastName" value="<?php echo $lastname; ?>">
<span class="error">* <?php echo $error['lastName'];?> </span>
<br><br>
Email:
<input type="text" name="email" value="<?php echo $email; ?>">
<span class="error">* <?php echo $error['email'];?> </span>
<br><br>
Password:
<input type="password" name="password" value="<?php echo $password; ?>">
<span class="error">* <?php echo $error['password'];?> </span>
<br><br>
Birthday:
<input type="date" name="birthday" value="<?php echo $birthday; ?>">
<span class="error">* <?php echo $error['birthday'];?> </span>
<br><br>
Gender:
<input type="radio" name="gender" value="Female"
<?php if (strcmp($gender, "Female") == 0) echo " checked"; ?> >Female
<input type="radio" name="gender" value="Male"
<?php if (strcmp($gender, "Male") == 0) echo " checked"; ?> >Male
<span class="error">* <?php echo $error['gender'];?> </span>
<br>
<span class="error"><?php echo $error['pictureURL'];?> </span><br>
<label for="file">Set profile picture:</label>
<input type="file" name="file" id="file"><br>
<input type="hidden" name="pictureURL" value="<?php echo $picture; ?>"><br>
<input class="submit" type="submit" name="submit" value="Save Changes">
</form>
</body>
</html>