Guest User

Untitled

a guest
Apr 3rd, 2018
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. <?php
  2. $fname = '';
  3. $lname = '';
  4. $email = '';
  5. $conn = '';
  6. if(isset($_POST ['register']))
  7. {
  8. // Assign local variables to form data
  9. $fname = trim($_POST['fname']);
  10. $lname = trim($_POST['lname']);
  11. $email = trim($_POST['email']);
  12.  
  13. $fname = stripcslashes($fname) ;
  14. $lname = stripcslashes($lname);
  15. $email = stripcslashes($email);
  16.  
  17. if(!empty($fname and $lname and $email)){
  18. // Connect to db
  19.  
  20.  
  21. // Validate if the email account already exists
  22. $query = "SELECT email FROM tbl_users WHERE email ='$email'";
  23. //$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
  24. $result = mysqli_query($conn, $query) or die(mysqli_error($conn));
  25.  
  26. $count = mysql_num_rows($result);
  27. /*
  28. echo $row[0];
  29. echo $count;
  30. echo $fname;
  31. echo $email;
  32. echo $lname;
  33. */
  34. // Generate random 32 character hash and assign it to a local variable.
  35. // Example output: f4552671f8909587cf485ea990207f3b
  36. $hash = md5( rand(0,1000) );
  37. $password = rand(1000,5000); // Generate random number between 1000 and 5000 and assign it to a local variable. // Example output: 4568
  38. $md5_password = md5($password) ;
  39.  
  40. if (empty($row = mysqli_fetch_array($result)))
  41. {
  42.  
  43. $to = $email; // Send email to our user
  44. $subject = 'Signup | Verification'; // Give the email a subject
  45. $message = '
  46.  
  47. Thanks for signing up!
  48. Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.
  49.  
  50. ------------------------
  51. Username: '.$email.'
  52. Temporary Password: '.$password.'
  53. ------------------------
  54.  
  55. Please click this link to activate your account:
  56. http://localhost/gurukul/user/verify.php?email='.$email.'&hash='.$hash.'
  57.  
  58. '; // Activation link -Concatenate email and md5 hash - direct to verify.php to validate the link
  59. // Our message above including the link
  60.  
  61. $headers = 'From:noreply@yourwebsite.com' . "rn"; // Set from headers
  62. $usertype = "Stu_Account";
  63. if(mail($to, $subject, $message, $headers)){// Send our email --- and if email sent successfully then insert data into db
  64. // Insert new user data into users table
  65. $query = "INSERT INTO tbl_users(f_name,l_name,email,hash,temp_password,user_type) VALUES ('$fname','$lname','$email','$hash','$md5_password','$usertype') ";
  66. $result = mysqli_query($conn, $query) or die(mysqli_error($conn));
  67. mysqli_close($conn);
  68.  
  69. // echo $md5_password;
  70. // echo 'check mail';
  71. // echo $password;
  72. ?>
  73. <script type="text/javascript">
  74. // history.back();
  75. window.location.replace("index.php");
  76. alert("Your account is successfully created! n An email is sent on your account. Please check your email shortly to activate your account. ");
  77. </script>
  78.  
  79. <?php
  80.  
  81. } else{
  82. ?>
  83. <script type="text/javascript">
  84. history.back();
  85. alert("Email Could Not be Sent. nnYour Account is Not Created, Try Again Shortly. n nPlease Contact Administator if the Issue Persists. ");
  86. </script>
  87. <?php
  88. }
  89. }else{
  90. // The Email Account is Already Registered';
  91. ?>
  92. <script type="text/javascript">
  93. history.back();
  94. alert("This email id is already registered.nn Please go to home page to login or create a new account with another email id.");
  95. </script>
  96. <?php
  97.  
  98. }
  99.  
  100. }else{
  101. ?>
  102. <script type="text/javascript">
  103. history.back();
  104. alert("Some data is missing, please enter all the details..");
  105. </script>
  106. <?php
  107. }
  108.  
  109. }
  110. ?>
Add Comment
Please, Sign In to add comment