Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function post_captcha($user_response) {
- $fields_string = '';
- $fields = array(
- 'secret' => '[SECRET KEY KEPT HIDDEN]',
- 'response' => $user_response
- );
- foreach($fields as $key=>$value)
- $fields_string .= $key . '=' . $value . '&';
- $fields_string = rtrim($fields_string, '&');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
- curl_setopt($ch, CURLOPT_POST, count($fields));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
- $result = curl_exec($ch);
- curl_close($ch);
- return json_decode($result, true);
- }
- $res = post_captcha($_POST['g-recaptcha-response']);
- if (!$res['success']) {
- $output = "<div class='warning-message'><b>Warning:</b>Complete the RECAPTCHA</div>";
- } else {
- if(isset($_POST['submit'])) {
- $username = strip_tags(stripslashes(mysqli_real_escape_string($conn, $_POST['username'])));
- $email = strip_tags(stripslashes(mysqli_real_escape_string($conn, $_POST['email'])));
- $password = $_POST['password'];
- $conpass = $_POST['conpass'];
- $passHash = password_hash($password, PASSWORD_BCRYPT);
- $usern = str_replace(' ','',$username);
- $ip = $_SERVER['REMOTE_ADDR'];
- if ($conpass !== $password) {
- $output = "<div class='warning-message'>Your passwords do not match!</div>";
- }
- $usercheck = $conn->query("SELECT username FROM users WHERE username='$username'");
- if ($usercheck->num_rows > 0) {
- $output = "<div class='warning-message'>Username is taken</div>";
- }
- $emailcheck = $conn->query("SELECT email FROM users WHERE email='$email'");
- if ($emailcheck->num_rows > 0) {
- $msg = "<div class='warning-message'>Email is taken.</div>";
- }
- if(strlen($username) < 3 || strlen($username) > 20){
- $output = "<div class='warning-message'><b>Warning:</b> Your Username must be 3-20 characters long.</div>";
- }
- if(strlen($password) < 6 || strlen($password) > 100) {
- $output = "<div class='warning-message'><b>Warning:</b> Your Password must be 6-100 characters long.</div>";
- }
- if(empty($output)) {
- $query = $conn->query("INSERT INTO `users`(username,email,password,ip,signupdate) VALUES ('$usern','$email','$passHash','$ip',$date')");
- if ($query) {
- header("Location: ../account/");
- }else {
- $output = "<div class='warning-message'><b>Warning: </b>An Error has occurred!</div>";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement