-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathedit_profile.php
More file actions
161 lines (160 loc) · 5.97 KB
/
edit_profile.php
File metadata and controls
161 lines (160 loc) · 5.97 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
<?php
//This page let an user edit his profile
include('config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
<title>Edit your profile</title>
</head>
<body>
<div class="header">
<a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Espace Membre" /></a>
</div>
<div class="content">
<?php
if(isset($_SESSION['username']))
{
$nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['userid'].'" and user1read="no") or (user2="'.$_SESSION['userid'].'" and user2read="no")) and id2="1"'));
$nb_new_pm = $nb_new_pm['nb_new_pm'];
?>
<div class="box">
<div class="box_left">
<a href="<?php echo $url_home; ?>">Forum Index</a> > Edit your profile
</div>
<div class="box_right">
<a href="list_pm.php">Your messages(<?php echo $nb_new_pm; ?>)</a> - <a href="profile.php?id=<?php echo $_SESSION['userid']; ?>"><?php echo htmlentities($_SESSION['username'], ENT_QUOTES, 'UTF-8'); ?></a> (<a href="login.php">Logout</a>)
</div>
<div class="clean"></div>
</div>
<?php
if(isset($_POST['username'], $_POST['password'], $_POST['passverif'], $_POST['email'], $_POST['avatar']))
{
if(get_magic_quotes_gpc())
{
$_POST['username'] = stripslashes($_POST['username']);
$_POST['password'] = stripslashes($_POST['password']);
$_POST['passverif'] = stripslashes($_POST['passverif']);
$_POST['email'] = stripslashes($_POST['email']);
$_POST['avatar'] = stripslashes($_POST['avatar']);
}
if($_POST['password']==$_POST['passverif'])
{
if(strlen($_POST['password'])>=6)
{
if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string(sha1($_POST['password']));
$email = mysql_real_escape_string($_POST['email']);
$avatar = mysql_real_escape_string($_POST['avatar']);
$dn = mysql_fetch_array(mysql_query('select count(*) as nb from users where username="'.$username.'"'));
if($dn['nb']==0 or $_POST['username']==$_SESSION['username'])
{
if(mysql_query('update users set username="'.$username.'", password="'.$password.'", email="'.$email.'", avatar="'.$avatar.'" where id="'.mysql_real_escape_string($_SESSION['userid']).'"'))
{
$form = false;
unset($_SESSION['username'], $_SESSION['userid']);
?>
<div class="message">Your profile have successfully been edited. You must login again.<br />
<a href="login.php">Login</a></div>
<?php
}
else
{
$form = true;
$message = 'An error occured while editing your profile.';
}
}
else
{
$form = true;
$message = 'Another user already uses this username.';
}
}
else
{
$form = true;
$message = 'The email you typed is not valid.';
}
}
else
{
$form = true;
$message = 'Your password must have a minimum of 6 characters.';
}
}
else
{
$form = true;
$message = 'The passwords you entered are not identical.';
}
}
else
{
$form = true;
}
if($form)
{
if(isset($message))
{
echo '<strong>'.$message.'</strong>';
}
if(isset($_POST['username'],$_POST['password'],$_POST['email']))
{
$username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
if($_POST['password']==$_POST['passverif'])
{
$password = htmlentities($_POST['password'], ENT_QUOTES, 'UTF-8');
}
else
{
$password = '';
}
$email = htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8');
$avatar = htmlentities($_POST['avatar'], ENT_QUOTES, 'UTF-8');
}
else
{
$dnn = mysql_fetch_array(mysql_query('select username,email,avatar from users where username="'.$_SESSION['username'].'"'));
$username = htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8');
$password = '';
$email = htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8');
$avatar = htmlentities($dnn['avatar'], ENT_QUOTES, 'UTF-8');
}
?>
<form action="edit_profile.php" method="post">
You can edit your informations:<br />
<div class="center">
<label for="username">Username</label><input type="text" name="username" id="username" value="<?php echo $username; ?>" /><br />
<label for="password">Password<span class="small">(6 characters min.)</span></label><input type="password" name="password" id="password" value="<?php echo $password; ?>" /><br />
<label for="passverif">Password<span class="small">(verification)</span></label><input type="password" name="passverif" id="passverif" value="<?php echo $password; ?>" /><br />
<label for="email">Email</label><input type="text" name="email" id="email" value="<?php echo $email; ?>" /><br />
<label for="avatar">Avatar<span class="small">(optional)</span></label><input type="text" name="avatar" id="avatar" value="<?php echo $avatar; ?>" /><br />
<input type="submit" value="Submit" />
</div>
</form>
<?php
}
}
else
{
?>
<h2>You must be logged to access this page:</h2>
<div class="box_login">
<form action="login.php" method="post">
<label for="username">Username</label><input type="text" name="username" id="username" /><br />
<label for="password">Password</label><input type="password" name="password" id="password" /><br />
<label for="memorize">Remember</label><input type="checkbox" name="memorize" id="memorize" value="yes" />
<div class="center">
<input type="submit" value="Login" /> <input type="button" onclick="javascript:document.location='signup.php';" value="Sign Up" />
</div>
</form>
</div>
<?php
}
?>
</body>
</html>