Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. <?php
  2.  
  3. require_once("config.php");
  4.  
  5. if (!isset ($_POST['submit'])) { ?>
  6.  
  7. <html>
  8. <head>
  9. <title>Register</title>
  10. <style type="text/css">
  11. background { background: #f2f2f2; font-family: Arial, sans-serif;}
  12. form { padding: 10px; background: #222; color: #fff; font-size: 16px; font-family: Arial, sans-serif; }
  13. .center { margin-left: auto; margin-right: auto; max-width: 450px; }
  14. </style>
  15. </head>
  16. <body>
  17. <div class="center">
  18. <form action="register.php" method="post">
  19. First Name: <input type="text" name="firstname" value="" /><br>
  20. Last Name: <input type="text" name="lastname" value="" /><br>
  21. Username: <input type="text" name="username" value="" /><br>
  22. Password: <input type="password" name="password" value="" /><br>
  23. Verify Password: <input type="password" name="verify" value="" /><br>
  24. <input type="submit" name="submit" />
  25. </form>
  26. </div>
  27. </body>
  28. </html>
  29.  
  30. <?php }
  31.  
  32. if (isset($_POST['submit'])) {
  33.  
  34. // define variables
  35. $username = $_POST['username'];
  36. $firstname = $_POST['firstname'];
  37. $lastname = $_POST['lastname'];
  38. $password = $_POST['password'];
  39. $verify = $_POST['verify'];
  40.  
  41. function checkEmpty($empty) {
  42. if (empty($empty))
  43. echo "<strong style=\"color:#ff0000;\">Field Required</strong>"; }
  44.  
  45. if (empty($username) || empty($firstname) || empty($lastname) || empty($password) || empty($verify)) { ?>
  46.  
  47. <html>
  48. <head>
  49. <title>Register</title>
  50. <style type="text/css">
  51. background { background: #f2f2f2; font-family: Arial, sans-serif;}
  52. form { padding: 10px; background: #222; color: #fff; font-size: 16px; font-family: Arial, sans-serif; }
  53. .center { margin-left: auto; margin-right: auto; max-width: 450px; }
  54. </style>
  55. </head>
  56. <body>
  57. <div class="center">
  58. <form action="register.php" method="post">
  59. First Name: <input type="text" name="firstname" value="<?php echo "$firstname"; ?>" /> <?php checkEmpty("$firstname"); ?><br>
  60. Last Name: <input type="text" name="lastname" value="<?php echo "$lastname"; ?>" /> <?php checkEmpty("$lastname"); ?><br>
  61. Username: <input type="text" name="username" value="<?php echo "$username"; ?>" /> <?php checkEmpty("$username"); ?><br>
  62. Password: <input type="password" name="password" value="<?php echo "$password"; ?>" /> <?php checkEmpty("$password"); ?><br>
  63. Verify Password: <input type="password" name="verify" value="<?php echo "$verify"; ?>" /> <?php checkEmpty("$verify"); ?><br>
  64. <input type="submit" name="submit" />
  65. </form>
  66. </div>
  67. </body>
  68. </html>
  69.  
  70. <?php }
  71.  
  72. else {
  73.  
  74. function cleanQuery($string)
  75. {
  76. $badWords = array("/delete/i", "/update/i","/union/i","/insert/i","/drop/i","/http/i","/--/i");
  77. $string = preg_replace($badWords, "", $string);
  78.  
  79. if(get_magic_quotes_gpc())
  80. $string = stripslashes($string);
  81. if (phpversion() >= '4.3.0')
  82. $string = mysql_real_escape_string($string);
  83. else
  84. $string = mysql_escape_string($string);
  85.  
  86. return $string;
  87. }
  88.  
  89. $username = cleanQuery($_POST['username']);
  90. $password = cleanQuery($_POST['password']);
  91. $firstname = ereg_replace("[^A-Za-z]", "", $_POST['firstname']);
  92. $lastname = ereg_replace("[^A-Za-z]", "", $_POST['lastname']);
  93. $mod_username = ereg_replace("[^A-Za-z0-9]", "", $username);
  94. $ip = $_SERVER[REMOTE_ADDR];
  95.  
  96. $query = mysql_query("INSERT INTO users (username,password,ip,firstname,lastname) VALUES ('$mod_username','".md5($password)."','$ip','$firstname','$lastname')") or die ("Registration Failed.");
  97.  
  98. echo "Welcome $_POST[username]! You've been successfully reigstered!<br /><br />
  99. please login <a href='login.php'><b>here</b></a>.";
  100.  
  101. exit();
  102. }
  103. }
  104.  
  105. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement