-
Notifications
You must be signed in to change notification settings - Fork 0
/
getUserBasics.php
270 lines (165 loc) · 6.48 KB
/
getUserBasics.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
// Returns an array with all basic user info
function getUserBasics($typeOfUser = "social") {
global $lastNames;
global $middleNames;
global $emailProviders;
global $states;
global $ages;
// global $subscribed;
global $logFileHandle;
/********************************************/
// password - only if trad user
if ($typeOfUser == "trad") {
$thisUser["password"] = rand(100, 999) . rand(100, 999) . rand(100, 999) . rand(100, 999);
}
/********************************************/
// birthday
$age = getRandomValue($ages, max(array_keys($ages)));
$yob = date("Y") - $age;
$thisUser["birthday"] = getBirthday($yob);
fwrite($logFileHandle, "<p>The yob is: " . $yob);
/*******************************************/
// gender
// $thisUser["gender"] = "female";
$thisUser["gender"] = getGender($age);
// if (rand(1,100) > 56) { $thisUser["gender"] = "male"; }
/*******************************************/
// givenName
$thisUser["givenName"] = getFirstName($thisUser["gender"], $yob);
/*******************************************/
// middleName
// just a middle initial
$thisUser["middleName"] = $middleNames[rand(0, (sizeof($middleNames) - 1))];
/*******************************************/
// familyName
$thisUser["familyName"] = $lastNames[rand(0, (sizeof($lastNames) - 1))];
// $fullname is used in creating the email address
// tom.g.smith
$fullName = strtolower($thisUser["givenName"] . "." . $thisUser["middleName"] . "." . $thisUser["familyName"]);
// Get rid of apostrophe in O'Connor, for example
$fullName = str_replace("'", "", $fullName);
fwrite($logFileHandle, "<p>The full name is: " . $fullName);
/*******************************************/
// email
$emailProvider = $emailProviders[rand(0, (sizeof($emailProviders) - 1))];
$thisUser["email"] = strtolower($fullName . "@" . $emailProvider);
/*******************************************/
// primaryAddress/country
$thisUser["primaryAddress"]["country"] = getCountry();
/*******************************************/
// primaryAddress>stateAbbreviation
if ($thisUser["primaryAddress"]["country"] == "United States") {
$thisUser["primaryAddress"]["stateAbbreviation"] = getRandomValue($states, max(array_keys($states)));
}
/******************************************/
// subscribed
// Newsletter subscription status
// $thisUser["subscribed"] = getRandomValue($subscribed);
/******************************************/
// Account created
$thisUser["createdFake"] = getAccountCreationDate($thisUser["gender"]);
fwrite($logFileHandle, "<p>The account creation date is: " . $thisUser["createdFake"]);
/******************************************/
// emailVerified
$thisEmail = getEmailVerifiedDate();
if (!empty($thisEmail)) { $thisUser["emailVerified"] = $thisEmail; }
/******************************************/
$thisUser["isAutogeneratedUser"] = "true";
/******************************************/
// Done!
return $thisUser;
}
function getAccountCreationDate($gender, $age) {
$minAge = 14;
// Male accounts are on average older than female accounts
// There is a 2/3 chance that a male account will be in the last two years
// There is a 1/3 chance that a male account will be in the last year
// Flipped for females
$x = rand(1,3);
$y = 730; // two years (365 * 2)
if ($gender == "male") {
if ($x == 1) { $y = 365; }
}
if ($gender == "female") {
if ($x != 1) { $y = 365; }
}
// Younger users created more recently
$y = $y + $age - $minAge;
$accountCreationDate = date('c', strtotime( '-'.mt_rand(1, $y).' days'));
return (strval($accountCreationDate));
}
// returns a dateTime string
function getEmailVerifiedDate() {
// 73% of users have a verified email, regardless of trad vs. social
// email has been verified within the last six months
$j = rand(1, 100);
if ($j <= 73) { $verifiedDate = date('c', strtotime( '-'.mt_rand(1,180).' days')); }
else { $verifiedDate = ""; }
return (strval($verifiedDate));
}
// Picks a random first name from the appropriate array
function getFirstName($gender, $yob) {
global $femaleFirstNames1990census;
global $femaleFirstNames1980_1989;
global $femaleFirstNames1990_1999;
global $maleFirstNames1990census;
global $maleFirstNames1980_1989;
global $maleFirstNames1990_1999;
$arrayNames = array();
$arrayNames["male"]["default"] = $maleFirstNames1990census;
$arrayNames["male"]["eighties"] = $maleFirstNames1980_1989;
$arrayNames["male"]["nineties"] = $maleFirstNames1990_1999;
$arrayNames["female"]["default"] = $femaleFirstNames1990census;
$arrayNames["female"]["eighties"] = $femaleFirstNames1980_1989;
$arrayNames["female"]["nineties"] = $femaleFirstNames1990_1999;
// Default
$listOfFnames = $arrayNames[$gender]["default"];
$j = rand(1, 10);
if ($yob >= 1980 && $yob <= 1989) {
if ($j >= 1 && $j <= 6) { $listOfFnames = $arrayNames[$gender]["eighties"]; }
if ($j >= 7 && $j <= 8) { $listOfFnames = $arrayNames[$gender]["nineties"]; }
}
if ($yob >= 1990) {
if ($j >= 1 && $j <= 6) { $listOfFnames = $arrayNames[$gender]["nineties"]; }
if ($j >= 7 && $j <= 8) { $listOfFnames = $arrayNames[$gender]["eighties"]; }
}
$fnamePos = rand(0, (sizeof($listOfFnames) - 1) );
return $listOfFnames[$fnamePos];
}
function getBirthday($yob) {
// global $ages;
// $age = getRandomValue($ages, max(array_keys($ages)));
// $yob = date("Y") - $age;
$month = rand(1, 12);
if ($month < 10) { $month = "0" . $month; }
$day = rand(1, 28);
if ($day < 10) { $day = "0" . $day; }
return ($yob . $month . $day);
}
function getCountry() {
global $countries;
$country = getRandomValue($countries, max(array_keys($countries)));
return $country;
}
function getGender($age) {
$gender = "female";
$x = rand(1,100);
if ($age >= 13 && $age <= 17 ) {
if ($x > 55) { $gender = "male"; }
return $gender;
}
if ($age >= 18 && $age <= 24 ) {
if ($x > 70) { $gender = "male"; }
return $gender;
}
if ($age >= 25 && $age <= 36 ) {
if ($x > 59) { $gender = "male"; }
return $gender;
}
if ($age >= 37 && $age <= 54 ) {
if ($x > 59) { $gender = "male"; }
return $gender;
}
return $gender;
}