Advertisement
Guest User

Untitled

a guest
May 11th, 2017
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 4.07 KB | None | 0 0
  1. //Functions.php
  2. <?php
  3. FUNCTION protect($string){
  4.     $string = mysql_real_escape_string($string);
  5.     $string = strip_tags($string);
  6.     $string = addslashes($string);
  7.    
  8.     RETURN $string;
  9. }
  10. FUNCTION CONNECT(){
  11.     $con = mysql_connect("localhost", "root", "******") OR die(mysql_error());
  12.     $db = mysql_select_db("members", $con);
  13. }
  14.  
  15.  
  16. ?>  
  17. <?php
  18. include_once "functions.php";
  19.  
  20. CONNECT();
  21.  
  22. IF(!$_POST['submit']){
  23.     echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";
  24.     echo "<form method=\"post\" action=\"register.php\">\n";
  25.     echo "<tr><td colspan=\"2\" align=\"center\">&nbsp;Registration</td></tr>\n";
  26.     echo "<tr><td>Username:</td><td><input type=\"text\" name=\"username\"></td></tr>\n";
  27.     echo "<tr><td>Password:</td><td><input type=\"password\" name=\"password\"></td></tr>\n";
  28.     echo "<tr><td>Confirm:</td><td><input type=\"password\" name=\"passconf\"></td></tr>\n";
  29.     echo "<tr><td>Email:</td><td><input type=\"text\" name=\"email\"></td></tr>\n";
  30.     echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Register\"></td></tr>\n";
  31.     echo "</form></table>\n";
  32. echo "<br><br>
  33. <br>
  34. <br>
  35. <br>
  36. <div align='bottom'>&copy; 2009-2010 <strong>Kazimiya</strong>. <a href='index'>Home</a> | <a href='irc'>IRC</a></div>";
  37. }ELSE {
  38.     $username = protect($_POST['username']);
  39.     $password = protect($_POST['password']);
  40.     $confirm = protect($_POST['passconf']);
  41.     $email = protect($_POST['email']);
  42.  
  43.    
  44.     $errors = array();
  45.    
  46.         IF(!$username){
  47.             $errors[] = "Username is not defined!";
  48.         }
  49.        
  50.         IF(!$password){
  51.             $errors[] = "Password is not defined!";
  52.         }
  53.        
  54.         IF($password){
  55.             IF(!$confirm){
  56.                 $errors[] = "Confirmation password is not defined!";
  57.             }
  58.         }
  59.        
  60.         IF(!$email){
  61.             $errors[] = "E-mail is not defined!";
  62.         }
  63.        
  64.  
  65.        
  66.         IF($username){
  67.             IF(!ctype_alnum($username)){
  68.                 $errors[] = "Username can only contain numbers and letters!";
  69.             }
  70.            
  71.             $range = range(1,32);
  72.             IF(!in_array(strlen($username),$range)){
  73.                 $errors[] = "Username must be between 1 and 32 characters!";
  74.             }
  75.         }
  76.        
  77.         IF($password && $confirm){
  78.             IF($password != $confirm){
  79.                 $errors[] = "Passwords do not match!";
  80.             }
  81.         }
  82.        
  83.         IF($email){
  84.             $checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
  85.             IF(!preg_match($checkemail, $email)){
  86.                 $errors[] = "E-mail is not valid, must be name@server.tld!";
  87.             }
  88.         }
  89.        
  90.  
  91.        
  92.         IF($username){
  93.             $sql = "SELECT * FROM `users` WHERE `username`='".$username."'";
  94.             $res = mysql_query($sql) OR die(mysql_error());
  95.            
  96.                 IF(mysql_num_rows($res) > 0){
  97.                     $errors[] = "The username you supplied is already in use!";
  98.                 }
  99.         }
  100.        
  101.         IF($email){
  102.             $sql2 = "SELECT * FROM `users` WHERE `email`='".$email."'";
  103.             $res2 = mysql_query($sql2) OR die(mysql_error());
  104.            
  105.                 IF(mysql_num_rows($res2) > 0){
  106.                     $errors[] = "The e-mail address you supplied is already in use of another user!";
  107.                 }
  108.         }
  109.        
  110.        
  111.         IF(COUNT($errors) > 0){
  112.             foreach($errors AS $error){
  113.                 echo $error . "<br>\n";
  114.             }
  115.         }ELSE {
  116.             $sql4 = "INSERT INTO `users`
  117.                    (`username`,`password`,`email`,`admin`,`time`)
  118.                    VALUES ('".$username."','".md5($password)."','".$email."','0','".TIME()."')";
  119.             $res4 = mysql_query($sql4) OR die(mysql_error());
  120.             echo "<br>
  121. You have successfully registered with the username <b>".$username."</b> and the password of <b>".$password."</b>!";
  122.         }
  123. }
  124.  
  125. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement