Advertisement
Guest User

Untitled

a guest
Sep 16th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. <?php
  2. if ($_GET['register'] == 'true') {
  3. registerUser();
  4. } else {
  5. echo "Invalid command.";
  6. }
  7.  
  8. function registerUser() {
  9.  
  10. $con = mysql_connect("localhost","root","aiden223");
  11. if (!$con)
  12. {
  13. die('Could not connect: ' . mysql_error());
  14. }
  15.  
  16. mysql_select_db("users", $con) or die(mysql_error());
  17.  
  18. $username = $_POST['user'];
  19. $password = $_POST['password'];
  20. $password2 = $_POST['password2'];
  21. $email = $_POST['email'];
  22.  
  23. $usernameValid = "YES";
  24. $passwordValid = "YES";
  25. $emailValid = "YES";
  26.  
  27. $usernameMessage = "";
  28. $passwordMessage = "";
  29. $emailMessage = "";
  30.  
  31. $finalPassword = "";
  32.  
  33. if (strlen($username) <3) {
  34. $usernameValid == "YES";
  35. } else {
  36. $usernameMessage == "Username is too short.";
  37. $usernameValid == "NO";
  38. }
  39.  
  40. if ($password == $password2) {
  41. $passwordValid == "YES";
  42. $finalPassword == md5($password);
  43. } else {
  44. $passwordMessage == "Invalid password.";
  45. $passwordValid == "NO";
  46. }
  47.  
  48. function checkEmail($email) {
  49. if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])
  50. ?*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",
  51. $email)){
  52. list($username,$domain)=split('@',$email);
  53. if(!checkdnsrr($domain,'MX')) {
  54. $emailValid == "NO";
  55. $emailMessage == "Invalid email address.";
  56. } else {
  57. $emailValid == "YES";
  58. }
  59. }
  60. }
  61.  
  62. if(($usernameValid == "YES") && ($passwordValid == "YES") && ($emailValid == "YES")) {
  63. $sql = "INSERT INTO users (username, password, email) VALUES ($username, $finalPassword, $email);";
  64. mysql_query($sql);
  65. $expire=time()+60*60*24;
  66. setcookie('user', $username, $expire);
  67. echo "<center><font face='Verdana' size='2'>Registration successful. You are now registered and logged in as " . $_COOKIE['user'] . ".";
  68. echo "<br />Click the button to go to the last page.</font>";
  69. echo "<br /><input type='button' value='Go back' onClick='history.go(-1)'></center>";
  70. } else {
  71. echo $passwordMessage;
  72. echo $usernameMessage;
  73. echo $emailMessage;
  74. }
  75. mysql_close($con);
  76. }
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement