Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include('configdb.php');
  4. if(isset($_POST['submit']))
  5. {
  6. //whether the username is blank
  7. if($_POST['username'] == '')
  8. {
  9. $_SESSION['error']['username'] = "User Name is required.";
  10. }
  11. //whether the email is blank
  12. if($_POST['email'] == '')
  13. {
  14. $_SESSION['error']['email'] = "E-mail is required.";
  15. }
  16. else
  17. {
  18. //whether the email format is correct
  19. if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $_POST['email']))
  20. {
  21. //if it has the correct format whether the email has already exist
  22. $email= $_POST['email'];
  23. $sql1 = "SELECT * FROM user WHERE email = '$email'";
  24. $result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());
  25. if (mysqli_num_rows($result1) > 0)
  26. {
  27. $_SESSION['error']['email'] = "This Email is already used.";
  28. }
  29. }
  30. else
  31. {
  32. //this error will set if the email format is not correct
  33. $_SESSION['error']['email'] = "Your email is not valid.";
  34. }
  35. }
  36. //whether the password is blank
  37. if($_POST['password'] == '')
  38. {
  39. $_SESSION['error']['password'] = "Password is required.";
  40. }
  41.  
  42. //if the error exist, we will go to registration form
  43. if(isset($_SESSION['error']))
  44. {
  45. header("Location: index.php");
  46. exit;
  47. }
  48. else
  49. {
  50. $username = $_POST['username'];
  51. $email = $_POST['email'];
  52. $password = $_POST['password'];
  53. $com_code = md5(uniqid(rand()));
  54.  
  55. $sql2 = "INSERT INTO user (username, email, password, com_code) VALUES ('$username', '$email', '$password', '$com_code')";
  56. $result2 = mysqli_query($mysqli,$sql2) or die(mysqli_error());
  57.  
  58. if($result2)
  59. {
  60. $to = $email;
  61. $subject = "Confirmation from TutsforWeb to $username";
  62. $header = "TutsforWeb: Confirmation from TutsforWeb";
  63. $message = "Please click the link below to verify and activate your account. rn";
  64. $message .= "http://www.yourname.com/confirm.php?passkey=$com_code";
  65.  
  66. $sentmail = mail($to,$subject,$message,$header);
  67.  
  68. if($sentmail)
  69. {
  70. echo "Your Confirmation link Has Been Sent To Your Email Address.";
  71. }
  72. else
  73. {
  74. echo "Cannot send Confirmation link to your e-mail address";
  75. }
  76. }
  77. }
  78. }
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement