Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Collect data
- $registrationData = [
- $_POST['firstname'],
- $_POST['lastname'],
- $_POST['email'],
- $_POST['phone'],
- $_POST['city'],
- $_POST['store'],
- $_POST['experience'],
- $_POST['event'],
- $_POST['time']
- ];
- //Stop progress entirely if registration data is incomplete
- foreach($registrationData as $data){
- if(!isset($data)){
- die("Incomplete Form Data");
- }
- }
- //Verify Re-Captcha
- $captcha_verify_post = [
- 'secret' => 'THANKS JONNY :)',
- 'response' => $_POST['g-recaptcha-response'],
- 'remoteip' => $_SERVER['REMOTE_ADDR']
- ];
- $ch = curl_init('https://www.google.com/recaptcha/api/siteverify');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $captcha_verify_post);
- $captcha_verified = json_decode(curl_exec($ch), true)["success"];
- curl_close($ch);
- //Stop if captcha failed
- if(! $captcha_verified){
- die("Incorrect Captcha");
- }
- //Connect to db
- $host = 'localhost';
- $user = 'bosch';
- $pass = '!p@55w0rd!';
- $db = 'bosch_registrants';
- $link = mysqli_connect($host, $user, $pass, $db);
- //Sanitize data
- function sanitize($data){
- global $link;
- $data = htmlspecialchars($data);
- $data = mysqli_real_escape_string($link, $data);
- return $data;
- }
- $registrationData = array_map("sanitize", $registrationData);
- //Add submission time and IP address to data
- date_default_timezone_set('America/New_York');
- array_push($registrationData, date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR']);
- //Insert into db
- mysqli_query($link,
- "INSERT INTO `registrants`(
- `firstname`,
- `lastname`,
- `email`,
- `phone`,
- `city`,
- `store`,
- `experience`,
- `event`,
- `time`,
- `submissiontime`,
- `ipaddress`
- )
- VALUES (" . implode(',', $registrationData) . ")"
- );
- mysqli_close($link);
- echo("success!");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement