Registratie mist?
Code (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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*UPDATE WIZARD */
if (isset($_POST['uname'])){
$prof ='';
$username = trim($_POST['uname']);
$email = trim($_POST['email']);
$pwd1 = trim($_POST['pwd1']);
$pwd2 = trim($_POST['pwd2']);
$v_code = md5(uniqid($username.'arikkerenregister', true));// add a secret word
/* update ip address */
$ip_addr = get_client_ip();
$ip_addr = $db->escape_string($ip_addr );
if($meta['forbid_ip'] == 'enabled'){
$ip_data = get_stat("SELECT count(*) as num FROM users WHERE ip_address ='".$ip_addr."' and web_id= ".$site_id."");
if ($ip_data->num != 0 ){
$r = array('status'=> 'error', 'text'=>$_t['ip_is_register_to_other_user']);
debug($r,config::debug);
}
}
/* end of update */
/* update 18 years */
$date_epoch = strtotime($_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']);
if( (time() - $date_epoch ) < 567648000 ){
$r = array('status'=> 'error', 'text'=>"You are under 18 years old" ,"reload"=>"https://www.google.com/");
debug($r,config::debug);
}
/* end */
if (strlen($username) <= 2 ){
$r = array('status'=> 'error', 'text'=>$_t['uname_min_err'] );
debug($r,config::debug);
}else{
$sql= "SELECT username from users WHERE username='".$db->escape_string($username)."'";
$result = $db->query($sql);
if ( $result->num_rows >= 1){
$r = array('status'=> 'error', 'text'=>$_t['uname_duplicate_err'] );
debug($r,config::debug);
}
$sql= "SELECT profile_name from user_profiles WHERE profile_name='".$db->escape_string($username)."' ";
$result = $db->query($sql);
if ( $result->num_rows >= 1){
$r = array('status'=> 'error', 'text'=>$_t['uname_duplicate_err'] );
debug($r,config::debug);
}
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$r = array('status'=> 'error', 'text'=>$_t['email_not_valid'] );
debug($r,config::debug);
}else{
$sql= "SELECT email from users WHERE email='".$db->escape_string($email)."'";
$result = $db->query($sql);
if ( $result->num_rows >= 1){
$r = array('status'=> 'error', 'text'=>$_t['email_duplicate_err'] );
debug($r,config::debug);
}
}
if (strlen($pwd1) <= 5 ){
$r = array('status'=> 'error', 'text'=>$_t['password_length_err'] );
debug($r,config::debug);
}elseif ($pwd1 !== $pwd2){
$r = array('status'=> 'error', 'text'=>$_t['password_not_match'] );
debug($r,config::debug);
}
/* check for proper site */
$meta_slave = get_slave_meta($site_id);
$meta = array_merge($meta,$meta_slave);
/* end of changes */
$sql= "INSERT INTO users (`username`, `role`, `password`, `state`, `email`, `credit`, `time_registered`, `is_online`, `verify_code`, ip_address, web_id)
VALUES ('".$db->escape_string($username)."', 'user', '".$db->escape_string(md5($pwd1))."',
'active', '".$db->escape_string($email)."', '".$meta['init_credit']."',NOW(), '0', '".$db->escape_string($v_code)."', '".$ip_addr."','".$site_id."' )";
if ($db->query($sql)){
$uid = $db->insert_id;
$land = explode('-',$_POST['province'],2);
$fname = strtolower($username);
$email_f = preg_replace('/[^a-zA-Z0-9-_]/','',$fname );
/* CREATE A PROFILE DIRECTLY*/
$sql= "INSERT INTO user_profiles (`user_id`, `profile_name`, `gender`, `birthdate`, `province`, `nation`, `length`, `physique`, `eye_color`, `hair_color`, `education`, `smoking`, `piercing`, `tattoo`, `aboutme`, `aboutyou`, `is_fake`, `looking_for`, `relationship`, `etnic`, `pubic_hair`,`fictional_email`, `cup_size`) VALUES (
'".$db->escape_string($uid)."',
'".$db->escape_string(strip_tags($username))."',
'".$db->escape_string($_POST['gender'])."',
'".$db->escape_string($_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'])."',
'".$db->escape_string($land[1])."',
'".$db->escape_string($land[0])."',
'".$db->escape_string(strip_tags($_POST['lengte']))."',
'".$db->escape_string($_POST['fisik'])."',
'".$db->escape_string($_POST['eye_color'])."',
'".$db->escape_string($_POST['hair_color'])."',
'".$db->escape_string($_POST['training'])."',
'".$db->escape_string($_POST['smoke'])."',
'".$db->escape_string($_POST['biseksual'])."',
'".$db->escape_string($_POST['tattoo'])."',
'".$db->escape_string(strip_tags(($_POST['overme'])))."',
'".$db->escape_string(strip_tags(($_POST['overyou'])))."',
'0',
'".$db->escape_string($_POST['gender_in'])."',
'".$db->escape_string($_POST['relatie'])."',
'".$db->escape_string($_POST['huidskleur'])."',
'".$db->escape_string($_POST['pubic_hair'])."',
'".$db->escape_string($email_f)."',
'".$db->escape_string($_POST['cupmaat'])."')";
if ( !$db->query($sql)){
$prof =$_t['failed_create_profile']." ". $db->error;
}else{
$f_id = $db->insert_id;
if(file_exists(__DIR__.'/images/'.$f_id.'_150x150_0.jpg'))
unlink(__DIR__.'/images/'.$f_id.'_150x150_0.jpg');
if(file_exists(__DIR__.'/images/'.$f_id.'_300x300_0.jpg'))
unlink(__DIR__.'/images/'.$f_id.'_300x300_0.jpg');
if(file_exists(__DIR__.'/images/'.$f_id.'_original_0.jpg'))
unlink(__DIR__.'/images/'.$f_id.'_original_0.jpg');
/* for interest */
/* add this user to site relation */
$db->query("insert into site_profile_relation (site_id, profile_id, is_fake_user) VALUES ('".$site_id."', '".$f_id."',0 )");
if(isset($_POST['interest'] )){
$db->query("delete from user_relation where type='interest' and id_profile='".$f_id."'");
foreach ($_POST['interest'] as $interest){
$db->query("INSERT INTO user_relation (`type`, `id_profile`, `id_interest`) VALUES ('interest', '".$f_id."', '".$db->escape_string($interest)."')");
}
}
$image2 ='img/no_image_'.$_POST['gender'].'.jpg';
$allowedExts = array("gif", "jpeg", "jpg", "png");
if (isset($_FILES["ppicture"]) ){
$extension = end(explode(".", $_FILES["ppicture"]["name"]));
if ((($_FILES["ppicture"]["type"] == "image/gif")|| ($_FILES["ppicture"]["type"] == "image/jpeg")|| ($_FILES["ppicture"]["type"] == "image/jpg")|| ($_FILES["ppicture"]["type"] == "image/pjpeg")|| ($_FILES["ppicture"]["type"] == "image/x-png")|| ($_FILES["ppicture"]["type"] == "image/png"))&& ($_FILES["ppicture"]["size"] < 2000000)&& in_array($extension, $allowedExts))
{
if ($_FILES["ppicture"]["error"] > 0){
$r = array('status'=> 'error', 'text'=>"fout: " . $_FILES["file"]["error"]);
debug($r,config::debug);
}else{
$source_path = $_FILES['ppicture']['tmp_name'];
$image2 = create_image($source_path, $f_id.'_150x150_0.jpg', 150, 150);
if ($image2 !==''){
$db->query("UPDATE user_profiles set profile_image = '".$image2 ."' where profile_id='".$f_id."' ");
create_image($source_path, $f_id.'_300x300_0.jpg', 300, 300);
move_uploaded_file($source_path,'images/'.$f_id.'_original_0.jpg');
$image = $image2 ;
}
}
}
}
/*SIGN IN AUTOMATICALLY*/
$_SESSION['user_id'] = $uid;
$_SESSION['username'] = $username;
$_SESSION['role'] = 'user';
$_SESSION['profile_id'] = $f_id ;
$_SESSION['image'] = $image2;
$_SESSION['imagexxx'] = $image2;
}
/*END OF */
/* REGISTER MINI VERSION */
if(isset($_POST['dest_mini']) and $_POST['dest_mini'] !== '' ){
if($_POST['msg_mini']){
stuur_mail($f_id, $_POST['dest_mini'],$_POST['msg_mini'] );
}
}
/* END */
/* SEND WELCOME MESSAGE */
$mess = get_stat("SELECT * FROM `auto_responder` WHERE type='welcome_message' and (site_id = '".$site_id."' or site_id=0) order by rand() LIMIT 1");
if(!empty($mess)){
$mess->content = str_replace('%profilename%',$username, $mess->content);
$sql = "INSERT INTO `messages` (`from`, `to`, `message`, `has_attachment`, `time_sending`, `mark`) VALUES (
'1',
'".$f_id ."',
'".$db->escape_string($mess->content)."',0,NOW(),'unread')";
$db->query($sql);
}
/* END OF */
$param = array('type'=>'account_activation','username'=>$username, "password" =>$pwd1, 'siteid'=>$site_id ,'contact_url'=>$uri.'contact.php');
kirim_email($email, $param, $meta);
$r = array('status'=> 'success', 'text'=>$_t['register_success']);
}else{
$r = array('status'=> 'error', 'text'=>$_t['register_failed'] );
}
debug($r,config::debug);
}
/* END OF UPDATE */
if (isset($_POST['uname'])){
$prof ='';
$username = trim($_POST['uname']);
$email = trim($_POST['email']);
$pwd1 = trim($_POST['pwd1']);
$pwd2 = trim($_POST['pwd2']);
$v_code = md5(uniqid($username.'arikkerenregister', true));// add a secret word
/* update ip address */
$ip_addr = get_client_ip();
$ip_addr = $db->escape_string($ip_addr );
if($meta['forbid_ip'] == 'enabled'){
$ip_data = get_stat("SELECT count(*) as num FROM users WHERE ip_address ='".$ip_addr."' and web_id= ".$site_id."");
if ($ip_data->num != 0 ){
$r = array('status'=> 'error', 'text'=>$_t['ip_is_register_to_other_user']);
debug($r,config::debug);
}
}
/* end of update */
/* update 18 years */
$date_epoch = strtotime($_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']);
if( (time() - $date_epoch ) < 567648000 ){
$r = array('status'=> 'error', 'text'=>"You are under 18 years old" ,"reload"=>"https://www.google.com/");
debug($r,config::debug);
}
/* end */
if (strlen($username) <= 2 ){
$r = array('status'=> 'error', 'text'=>$_t['uname_min_err'] );
debug($r,config::debug);
}else{
$sql= "SELECT username from users WHERE username='".$db->escape_string($username)."'";
$result = $db->query($sql);
if ( $result->num_rows >= 1){
$r = array('status'=> 'error', 'text'=>$_t['uname_duplicate_err'] );
debug($r,config::debug);
}
$sql= "SELECT profile_name from user_profiles WHERE profile_name='".$db->escape_string($username)."' ";
$result = $db->query($sql);
if ( $result->num_rows >= 1){
$r = array('status'=> 'error', 'text'=>$_t['uname_duplicate_err'] );
debug($r,config::debug);
}
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$r = array('status'=> 'error', 'text'=>$_t['email_not_valid'] );
debug($r,config::debug);
}else{
$sql= "SELECT email from users WHERE email='".$db->escape_string($email)."'";
$result = $db->query($sql);
if ( $result->num_rows >= 1){
$r = array('status'=> 'error', 'text'=>$_t['email_duplicate_err'] );
debug($r,config::debug);
}
}
if (strlen($pwd1) <= 5 ){
$r = array('status'=> 'error', 'text'=>$_t['password_length_err'] );
debug($r,config::debug);
}elseif ($pwd1 !== $pwd2){
$r = array('status'=> 'error', 'text'=>$_t['password_not_match'] );
debug($r,config::debug);
}
/* check for proper site */
$meta_slave = get_slave_meta($site_id);
$meta = array_merge($meta,$meta_slave);
/* end of changes */
$sql= "INSERT INTO users (`username`, `role`, `password`, `state`, `email`, `credit`, `time_registered`, `is_online`, `verify_code`, ip_address, web_id)
VALUES ('".$db->escape_string($username)."', 'user', '".$db->escape_string(md5($pwd1))."',
'active', '".$db->escape_string($email)."', '".$meta['init_credit']."',NOW(), '0', '".$db->escape_string($v_code)."', '".$ip_addr."','".$site_id."' )";
if ($db->query($sql)){
$uid = $db->insert_id;
$land = explode('-',$_POST['province'],2);
$fname = strtolower($username);
$email_f = preg_replace('/[^a-zA-Z0-9-_]/','',$fname );
/* CREATE A PROFILE DIRECTLY*/
$sql= "INSERT INTO user_profiles (`user_id`, `profile_name`, `gender`, `birthdate`, `province`, `nation`, `length`, `physique`, `eye_color`, `hair_color`, `education`, `smoking`, `piercing`, `tattoo`, `aboutme`, `aboutyou`, `is_fake`, `looking_for`, `relationship`, `etnic`, `pubic_hair`,`fictional_email`, `cup_size`) VALUES (
'".$db->escape_string($uid)."',
'".$db->escape_string(strip_tags($username))."',
'".$db->escape_string($_POST['gender'])."',
'".$db->escape_string($_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'])."',
'".$db->escape_string($land[1])."',
'".$db->escape_string($land[0])."',
'".$db->escape_string(strip_tags($_POST['lengte']))."',
'".$db->escape_string($_POST['fisik'])."',
'".$db->escape_string($_POST['eye_color'])."',
'".$db->escape_string($_POST['hair_color'])."',
'".$db->escape_string($_POST['training'])."',
'".$db->escape_string($_POST['smoke'])."',
'".$db->escape_string($_POST['biseksual'])."',
'".$db->escape_string($_POST['tattoo'])."',
'".$db->escape_string(strip_tags(($_POST['overme'])))."',
'".$db->escape_string(strip_tags(($_POST['overyou'])))."',
'0',
'".$db->escape_string($_POST['gender_in'])."',
'".$db->escape_string($_POST['relatie'])."',
'".$db->escape_string($_POST['huidskleur'])."',
'".$db->escape_string($_POST['pubic_hair'])."',
'".$db->escape_string($email_f)."',
'".$db->escape_string($_POST['cupmaat'])."')";
if ( !$db->query($sql)){
$prof =$_t['failed_create_profile']." ". $db->error;
}else{
$f_id = $db->insert_id;
if(file_exists(__DIR__.'/images/'.$f_id.'_150x150_0.jpg'))
unlink(__DIR__.'/images/'.$f_id.'_150x150_0.jpg');
if(file_exists(__DIR__.'/images/'.$f_id.'_300x300_0.jpg'))
unlink(__DIR__.'/images/'.$f_id.'_300x300_0.jpg');
if(file_exists(__DIR__.'/images/'.$f_id.'_original_0.jpg'))
unlink(__DIR__.'/images/'.$f_id.'_original_0.jpg');
/* for interest */
/* add this user to site relation */
$db->query("insert into site_profile_relation (site_id, profile_id, is_fake_user) VALUES ('".$site_id."', '".$f_id."',0 )");
if(isset($_POST['interest'] )){
$db->query("delete from user_relation where type='interest' and id_profile='".$f_id."'");
foreach ($_POST['interest'] as $interest){
$db->query("INSERT INTO user_relation (`type`, `id_profile`, `id_interest`) VALUES ('interest', '".$f_id."', '".$db->escape_string($interest)."')");
}
}
$image2 ='img/no_image_'.$_POST['gender'].'.jpg';
$allowedExts = array("gif", "jpeg", "jpg", "png");
if (isset($_FILES["ppicture"]) ){
$extension = end(explode(".", $_FILES["ppicture"]["name"]));
if ((($_FILES["ppicture"]["type"] == "image/gif")|| ($_FILES["ppicture"]["type"] == "image/jpeg")|| ($_FILES["ppicture"]["type"] == "image/jpg")|| ($_FILES["ppicture"]["type"] == "image/pjpeg")|| ($_FILES["ppicture"]["type"] == "image/x-png")|| ($_FILES["ppicture"]["type"] == "image/png"))&& ($_FILES["ppicture"]["size"] < 2000000)&& in_array($extension, $allowedExts))
{
if ($_FILES["ppicture"]["error"] > 0){
$r = array('status'=> 'error', 'text'=>"fout: " . $_FILES["file"]["error"]);
debug($r,config::debug);
}else{
$source_path = $_FILES['ppicture']['tmp_name'];
$image2 = create_image($source_path, $f_id.'_150x150_0.jpg', 150, 150);
if ($image2 !==''){
$db->query("UPDATE user_profiles set profile_image = '".$image2 ."' where profile_id='".$f_id."' ");
create_image($source_path, $f_id.'_300x300_0.jpg', 300, 300);
move_uploaded_file($source_path,'images/'.$f_id.'_original_0.jpg');
$image = $image2 ;
}
}
}
}
/*SIGN IN AUTOMATICALLY*/
$_SESSION['user_id'] = $uid;
$_SESSION['username'] = $username;
$_SESSION['role'] = 'user';
$_SESSION['profile_id'] = $f_id ;
$_SESSION['image'] = $image2;
$_SESSION['imagexxx'] = $image2;
}
/*END OF */
/* REGISTER MINI VERSION */
if(isset($_POST['dest_mini']) and $_POST['dest_mini'] !== '' ){
if($_POST['msg_mini']){
stuur_mail($f_id, $_POST['dest_mini'],$_POST['msg_mini'] );
}
}
/* END */
/* SEND WELCOME MESSAGE */
$mess = get_stat("SELECT * FROM `auto_responder` WHERE type='welcome_message' and (site_id = '".$site_id."' or site_id=0) order by rand() LIMIT 1");
if(!empty($mess)){
$mess->content = str_replace('%profilename%',$username, $mess->content);
$sql = "INSERT INTO `messages` (`from`, `to`, `message`, `has_attachment`, `time_sending`, `mark`) VALUES (
'1',
'".$f_id ."',
'".$db->escape_string($mess->content)."',0,NOW(),'unread')";
$db->query($sql);
}
/* END OF */
$param = array('type'=>'account_activation','username'=>$username, "password" =>$pwd1, 'siteid'=>$site_id ,'contact_url'=>$uri.'contact.php');
kirim_email($email, $param, $meta);
$r = array('status'=> 'success', 'text'=>$_t['register_success']);
}else{
$r = array('status'=> 'error', 'text'=>$_t['register_failed'] );
}
debug($r,config::debug);
}
/* END OF UPDATE */
Ik weet dat de code een beetje overdreven groot is, dit is wat in ajax.php staat? Maar hoe krijgt hij er een registratie formulier bij?
Groetjes
- Zorg voor de validatie en invoercontroles (wachtwoord ingevuld? Juiste email-adresformaat etc...)
- Zorg voor spam-beveiligingen tegen spambotjes.
- Zorg ervoor dat je de invoer dan in de database opslaat.
Maar zo te zien is dit al een registratie-script?
Gewijzigd op 13/07/2020 17:39:49 door - Ariën -
Dat dacht ik ook inderdaad enkel blijkt dit niet zo te zijn want dit is de verwerking in ajax.. en daar werkt sowieso niets en formulier weet ik op dit gebeuren even zo niet te bouwen eigenlijk.
Heb je in de developerstools van je browser al gekeken naar wat je AJAX-request doet? Zet ook de error-reporting aan:
Code (php)
1
2
3
4
5
2
3
4
5
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
Gewijzigd op 13/07/2020 17:47:44 door - Ariën -
Ik had een deel gemaakt een klein formuliertje die dan verwijst naar de ajax.php enkel doet hij wel de foutmeldingen weergeven maar niet de gelukte deel, ik weet gewoon niet eens hoe ik dit allemaal zou moeten verwerken naar een werkend iets zeg maar
Waar loop je precies op vast? Wat heb je al? Een concretere vraagstelling lijkt me praktischer voor hulp.
Nu ja, eigenlijk heel snel en dom gezegd haha heb ik hier een formulier bij nodig waarbij men kan kiezen man, vrouw als dropdown en dergelijke en dat het dan gewoon werkt..
Dus hoe en waar alle bestanden en scripts geslagen worden, hoe de scripts samengesteld zijn, hoe ze opgeroepen worden (procedureel, of in classes/functies), en waar staat de layout opgeslagen (in de applicatie zelf geweven, of in template-bestanden)?
Als je dit een beetje inzichtelijk voor jezelf hebt gemaakt kan je ook een plan van aanpak maken.
Wat ik hier zie is een AJAX-script, die onderhuids onderdeel zal zijn van een formulier.
In het formulier kan je dan aangeven wat iemands geslacht is, waarna je dit moet verwerken in je AJAX-script.
En is het dan niet heel handig/snel te maken in een normaal formulier dan in plaats van ajax?
Gewijzigd op 13/07/2020 18:22:33 door - Ariën -
Heb jij eventueel een heel klein werkend voorbeeldje die ik dan kan aanpassen? Waar in staat wanneer email of gebruiker al aangemeld is dat het niet nog een keer kan en wachtwoord overeenkomt en dan met de query voor users.. de rest red ik me dan wel mee denk ik... hoop dat dat mogelijk is? en excuses!
Code (php)
Het wachtwoord zou ik niet meer met md5() doen. Dat is hopeloos ouderwets.
Gebruik liever password_hash() om een wachtwoord te genereren en password_verify() om deze te controleren.