Advertisement
Guest User

Untitled

a guest
Jan 14th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.86 KB | None | 0 0
  1.  
  2. <?php
  3. $trueornot = false; // defining a checker variable
  4. $secret = '6LchoxEUAAAAABYh_YqXNpM7YX_VYQCVXqGhKLZi'; // google secret key
  5. $response = $_POST['g-recaptcha-response']; // taking google recaptcha's response
  6. $userip = $_SERVER['REMOTE_ADDR']; // taking the remote ip adress of the user
  7. $url = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$response&remoteip=$userip"); // connecting to google's recaptcha confirm
  8.  
  9. $resultarray = json_decode($url , TRUE);
  10. if ($resultarray['success'] == 1) { // checking if user is not a bot
  11.     $trueornot = true;
  12. } else {
  13.     echo "<script>alert('Please complete the Captcha!')</script>"; // notifing the user he didn't complete the captcha
  14.     $trueornot = false;
  15.     header( "refresh:0.00001;url=index.html" ); // redirecting to the same page
  16. }
  17. if(isset($_POST['submit1']) && $trueornot)  // checking if the submit button is clicked and if the user has completed the captcha
  18. {
  19.        
  20.                 $myApplicationSalt = '$6$1234567890123456'; // application salt
  21.                 // database variables
  22.                 $db_server = 'localhost';
  23.                 $db_name = 'root';
  24.                 $db_password = "";
  25.                 $db = "loginregister";
  26.                 // connecting to the database
  27.                 $conn = mysqli_connect($db_server,$db_name,$db_password,$db);
  28.                 // collecting data
  29.                 $a = 0;
  30.                 $password = $_POST['pw'];
  31.                 $firstname = $_POST['fname'];
  32.                 $lastname = $_POST['lname'];
  33.                 $username = $_POST['uname'];
  34.                 $email = $_POST['email'];
  35.                 // making sure it has no mysqli injections
  36.                 $firstname = mysqli_real_escape_string($conn , $firstname);
  37.                 $lastname = mysqli_real_escape_string($conn , $lastname);
  38.                 $username = mysqli_real_escape_string($conn , $username);
  39.                 $email = mysqli_real_escape_string($conn , $email);
  40.                 // encrypting the password
  41.                 $password = md5($password);
  42.                 // selecting every account from the existing database where the email equals to the email the user has submitted
  43.                 $sql = "SELECT email FROM registration WHERE email='".$email."'";
  44.                 $result = mysqli_query($conn , $sql);
  45.                 $row = mysqli_fetch_array($result , MYSQLI_ASSOC); // fetching the row
  46.                 if (mysqli_num_rows($result) == 1) { // checking if email is already in use
  47.                     echo "<script>window.alert('This email is already in use!')</script>";
  48.                     header( "refresh:0;url='index.html'");
  49.                 } else {
  50.                 $sqlu = "SELECT uname FROM registration WHERE uname='".$username."'"; // selecting every account from the existing database where the username equals the username the user has submitted
  51.                 $result1 = mysqli_query($conn , $sqlu);
  52.                 $row1 = mysqli_fetch_array($result1 , MYSQLI_ASSOC); // fetching the row
  53.                 if (mysqli_num_rows($result1) == 1) { // checking if username is already in use
  54.                     echo "<script>window.alert('This username is already in use!')</script>";
  55.                     header( "refresh:0;url='index.html'"); // redirecting
  56.                 } else {
  57.                     $query = mysqli_query($conn , "INSERT INTO registration(fname , lname , uname , email , pw)VALUES ('$firstname' , '$lastname' , '$username' , '$email' , '$password')"); // sending the database our variables
  58.                     $a = 1;
  59.                     }
  60.                 }
  61.                 if ($a == 1) { // finishing the registration and redirecting the user
  62.                     echo "You are now registered!";
  63.                     header( "refresh:2;url=../login.php" );
  64.  
  65.                 }
  66.             }
  67.  
  68.  
  69.  
  70.    
  71.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement