· 9 years ago · Oct 30, 2016, 06:02 PM
1 <?php
2 //connect to database
3 require 'includes/database.php';
4 // set default time to UTC
5 date_default_timezone_set('UTC');
6 // define variables and set to empty values
7 $username = $ip = $email = $gender = $country = $age = $playtime = $onlinetime = $comments = $done = $youtubeChannel = $properEnglish = "";
8 //recieve all variables
9 $username=$_POST['username'];
10 $email=$_POST['email'];
11 $country=$_POST['country'];
12 $age=$_POST['age'];
13 $gender=$_POST['gender'];
14 $playtime=$_POST['playtime'];
15 $onlinetime=$_POST['onlinetime'];
16 $comments=$_POST['comments'];
17 $youtubeChannel=$_POST['youtubeChannel'];
18 $properEnglish=$_POST['properEnglish'];
19
20//set Date & ip
21 $date=date('l jS \of F Y h:i:s A');
22 $ip = $_SERVER['REMOTE_ADDR'];
23//$ip is used by the captcha too!
24 //set to not done.
25 $done = false;
26
27/* Old captcha code (NOT WORKING)
28*$captcha_secret="XXX";
29*$captcha_response=$_POST["g-recaptcha-response"];
30*$captcha_verify="file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret={$captcha_secret}&response={$captcha_response}')";
31*$captcha_success=json_decode($captcha_verify);
32*if ($captcha_success->success==false) {
33* $Err = "reCaptcha Invalid";
34* exit($Err);
35*}
36*/
37//captcha
38 $captcha=$_POST['g-recaptcha-response'];
39 if(!$captcha){
40 echo '<h2>Please check the captcha form.</h2>';
41 exit;
42 }
43 $secretKey = "Ya won't see it";
44 $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
45 $responseKeys = json_decode($response,true);
46 if(intval($responseKeys["success"]) !== 1) {
47 $Err = "Captcha incorrect (Multiple times!)";
48 exit($Err);
49 }
50//captcha end
51
52 //validation
53 //validate username, a-z A-Z 0-9
54 if (preg_match('/^[A-Za-z0-9_]+$/', $country)) {
55 } else {
56 $Err = "Username incorrect";
57 exit($Err);
58 }
59 //validate for email
60 if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
61 $Err = "Invalid email format";
62 exit($Err);
63 }
64 //validate for 2 letter input
65 if (preg_match('/^[a-zA-Z]{2}$/', $country)) {
66 } else {
67 $Err = "Country incorrect, Please use your country 2 letter code";
68 exit($Err);
69 }
70 //validate age for numeric only
71 if (ctype_digit($age)) {
72 } else {
73 $Err = "Age incorrect, only use numbers";
74 exit($Err);
75 }
76 //validate playtime for numeric only
77 if (ctype_digit($playtime)) {
78 } else {
79 $Err = "Time you play Minecraft incorrect, only use numbers";
80 exit($Err);
81 }
82 //validate onlinetime for numeric only
83 if (ctype_digit($onlinetime)) {
84 } else {
85 $Err = "Time you woud be online incorrect, only use numbers";
86 exit($Err);
87 }
88 //validate youtube channel
89 //if (isset($youtubeChannel)) {
90 // if (!filter_var($youtubeChannel, FILTER_VALIDATE_URL) === false) {
91 // $Err = "Youtube channel link is incorrect, Leave empty or fill in a correct link.";
92 // exit($Err);
93 // }
94 //remove ' from comments
95 if (preg_match('/'.preg_quote('^\'£$%^&*()}{@#~?><,@|-=-_+-¬', '/').'/', $string)) {
96 $Err = "Please do not use any Special characters in your comments.";
97 exit($Err);
98 }
99
100 //validate CanSpeakProperEnglish
101/*
102**************IMPORTANT*******************
103*Make a Boolean validotor
104*Still got to do this stuff!!!!!!
105******************************************
106*/
107
108
109 //maildata
110 $mailsubject = "Hermitcraft Whitelist application";
111 $mailmessage = "Hello $username,\n \nYou have been sucessfully added to the Hermitcraft Waiting list.\nThe next data was submitted:\nUsername: $username\nEmail: $email\nCountry: $country\nAge: $age\ngender: $gender\nTime you play Minecraft: $playtime Years\nHours per week online: $onlinetime\nComments (optional): $comments\nYoutube link (optional): $youtubelink\nIf you speak Proper english: $properEnglish\n \nThanks for Applicating,\nyou will recieve an message when you are accepted (or declined).";
112 //insert to database
113 mysqli_query($connect,"INSERT INTO users(username,done,email,country,ip,age,gender,playtime,onlinetime,comments,youtubelink,properEnglish,date)
114 VALUES ('$username','$done','$email','$country','$ip','$age','$gender','$playtime','$onlinetime','$comments','$youtubelink','$properEnglish','$date')");
115 if(mysqli_affected_rows($connect) > 0){
116 //Send mail
117 //mail($email,$mailsubject,$mailmessage);
118 } else { }
119 ?>
120 <!--End of Php processing area-->
121<html>
122 <head>
123 <title>Hermitcraft whitelist Application</title>
124 <link rel="stylesheet" type="text/css" href="./css/style.css">
125 </head>
126 <body>
127 <div class="form">
128<?php
129 if(mysqli_affected_rows($connect) > 0){
130 echo "<p>Sucessfully added to Waiting list!</p>";
131} else {
132 echo "NOT Added to waiting list Error:<br />";
133 echo mysqli_error ($connect);
134 echo "<br />Please notify the staff for solving this issue.";
135}
136?>
137</div>
138 </body>
139 <footer>
140 </footer>
141</html>