-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.php
65 lines (59 loc) · 1.8 KB
/
process.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
<?php
require_once 'db.php';
$erros = array();
$data = array();
$email = $_POST['email'];
$recaptcha = $_POST['g-recaptcha-response'];
$session_id = $_POST['sid'];
// $age = $_POST['age'];
// Random string generator
function generateRandomString($length = 15) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
$safety_string = generateRandomString();
if(empty($email)) {
$errors['email'] = 'Please enter your email';
}
if(empty($_POST['age'])) {
$errors['age'] = 'Confirm age';
}
if(empty($recaptcha)) {
$errors['recaptcha'] = 'empty_recaptcha';
}
if(empty($session_id)) {
$errors['session_id'] = '';
}
// if errors exist ======================
if(!empty($errors)) {
$data['errors'] = $errors;
$data['success'] = false;
}
// if no errors exist ===================
else {
// VALIDATE CAPTCHA =================
$secret = '6LelSDQUAAAAAOJfN7q0Xnnyjtd92iya7B8wLDjI';
//get verify response data
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $recaptcha);
$responseData = json_decode($verifyResponse);
if ($responseData->success) { // If recpatcha response verified
$data['success'] = true;
$data['message'] = 'success';
$data['safety_string'] = $safety_string;
// Insert into database
DB::insert('flavors_games_registered_users', array(
'email' => $email,
'safety_string' => $safety_string,
'session_id' => $session_id
));
}
else { // If recpatcha response not verified
$data['message'] = 'robot_verification_failed';
}
}
echo json_encode($data);