Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.60 KB | None | 0 0
  1. <?php include_once 'connect.php'; ?>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  3. <html>
  4.     <head>
  5.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6.         <link href="style.css" rel="stylesheet" type="text/css" />
  7.         <title>Tutorial MMORPG</title>
  8.     </head>
  9.     <body>
  10. <div id="reg_page">
  11. <?php
  12.  
  13. function reg_form($max, $maxPass, $player = null, $password=null, $pass2 = null, $email = null, $class = null){
  14.     // Displays the register form when needed.
  15.     echo '<br>
  16.    <div id="reg_form">
  17.    <form method="post" action="register.php">
  18.        Desired Username: <input type="text" name="player" size="'.$max.'" value="'.$player.'"><br>
  19.        Password: <input type="password" name="password" size="'.$maxPass.'" value="'.$password.'"><br>
  20.        Retype Password: <input type="password" name="pass2" size="'.$maxPass.'" value="'.$pass2.'"><br>
  21.        Email Address: <input type="text" name="email" size="55" value="'.$email.'"><br>
  22.        <input type="submit" value="Register">';
  23.  
  24.     echo "</form>
  25.    </div>";
  26.  
  27.     echo '<center><a href="./index.php">Back to Homepage</a><center>';
  28.  
  29. /**
  30. Validate an email address.
  31. Provide email address (raw input)
  32. Returns true if the email address has the email
  33. address format and the domain exists.
  34. */
  35. function checkEmail($email)
  36. {
  37.    $isValid = true;
  38.    $atIndex = strrpos($email, "@");
  39.    if (is_bool($atIndex) && !$atIndex)
  40.    {
  41.       $isValid = false;
  42.    }
  43.    else
  44.    {
  45.       $domain = substr($email, $atIndex+1);
  46.       $local = substr($email, 0, $atIndex);
  47.       $localLen = strlen($local);
  48.       $domainLen = strlen($domain);
  49.       if ($localLen < 1 || $localLen > 64)
  50.       {
  51.          // local part length exceeded
  52.          $isValid = false;
  53.       }
  54.       else if ($domainLen < 1 || $domainLen > 255)
  55.       {
  56.          // domain part length exceeded
  57.          $isValid = false;
  58.       }
  59.       else if ($local[0] == '.' || $local[$localLen-1] == '.')
  60.       {
  61.          // local part starts or ends with '.'
  62.          $isValid = false;
  63.       }
  64.       else if (preg_match('/\\.\\./', $local))
  65.       {
  66.          // local part has two consecutive dots
  67.          $isValid = false;
  68.       }
  69.       else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
  70.       {
  71.          // character not valid in domain part
  72.          $isValid = false;
  73.       }
  74.       else if (preg_match('/\\.\\./', $domain))
  75.       {
  76.          // domain part has two consecutive dots
  77.          $isValid = false;
  78.       }
  79.       else if
  80. (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
  81.                  str_replace("\\\\","",$local)))
  82.       {
  83.          // character not valid in local part unless
  84.          // local part is quoted
  85.          if (!preg_match('/^"(\\\\"|[^"])+"$/',
  86.              str_replace("\\\\","",$local)))
  87.          {
  88.             $isValid = false;
  89.          }
  90.       }
  91.       if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
  92.       {
  93.          // domain not found in DNS
  94.          $isValid = false;
  95.       }
  96.    }
  97.    return $isValid;
  98. }
  99.  
  100.  
  101.  
  102. if($_POST){
  103.     // Grabbing the information the user filled out.
  104.     $player = strip_tags($_POST['player']);
  105.     $password = $_POST['password'];
  106.     $pass2 = $_POST['pass2'];
  107.     $email = strip_tags($_POST['email']);
  108.  
  109.     // Here you can change the maximum or minimum number of characters allowed
  110.     // for usernames and passwords. Just change it here and the rest of the code
  111.     // takes care of it.
  112.     $maxNameLength = 30;
  113.     $minNameLength = 4;
  114.     $maxPassLength = 15;
  115.     $minPassLength = 6;
  116.  
  117.  
  118.     // Error finder - Checks every possibility in order of importance so that
  119.     //                it only checks or sees errors that matter.
  120.     $completeError = "<ul> \n";
  121.     $errorz = 0;
  122.     if(strlen($player) > $maxNameLength){
  123.         $completeError .= "<li>Username is too long. (".$minNameLength."-".$maxNameLength." character limit)</li> \n";
  124.         $errorz = 1;
  125.     } elseif (strlen($player) < $minNameLength){
  126.         $completeError .= "<li>Username is too short. (".$minNameLength."-".$maxNameLength." character limit)</li> \n";
  127.         $errorz = 1;
  128.     } else {
  129.         $query = "SELECT * FROM players WHERE name='$player'";
  130.         $result = mysql_query($query) or die("Could not query players table");
  131.         $result = mysql_fetch_array($result);
  132.         if($result){
  133.             $completeError .= "<li>Username has already been taken. Please come up with another.</li> \n";
  134.             $errorz = 1;
  135.         }
  136.     }
  137.  
  138.     if(!$password || !$pass2){
  139.         $completeError .= "<li>You didn't fill out one of the password fields.</li> \n";
  140.         $errorz = 1;
  141.     } elseif (strlen($password) > $maxPassLength) {
  142.         $completeError .= "<li>Your password is too long. (".$minPassLength."-".$maxPassLength." character limit)</li> \n";
  143.         $errorz = 1;
  144.     } elseif (strlen($password) < $minPassLength) {
  145.         $completeError .= "<li>Your password is too short. (".$minPassLength."-".$maxPassLength." character limit)</li> \n";
  146.         $errorz = 1;
  147.     } elseif ($password != $pass2){
  148.         $completeError .= "<li>Your passwords do not match.</li> \n";
  149.         $errorz = 1;
  150.     }
  151.  
  152.     if (!$email){
  153.         $completeError .= "<li>You didn't fill in your email address.</li> \n";
  154.         $errorz = 1;
  155.     } elseif (!checkEmail($email)){
  156.         $completeError .= "<li>You did not enter a valid email address.</li> \n";
  157.         $errorz = 1;
  158.     } else {
  159.         $query = "SELECT * FROM players WHERE email='$email'";
  160.         $result = mysql_query($query) or die("Not able to query for email");
  161.         $result = mysql_fetch_array($result);
  162.         if($result){
  163.             $completeError .= "<li>Someone has already registered with that email address.</li> \n";
  164.             $errorz = 1;
  165.         }
  166.     }
  167.     $completeError .= "</ul> \n";
  168.     // END ERROR FINDER
  169.  
  170.  
  171.     // Error handler - Either displays errors with the register form or just
  172.     //                 registers the user
  173.     if ($errorz){
  174.         echo "<div id='reg_error'>The following error(s) occurred: \n";
  175.         echo $completeError;
  176.         echo "</div>";
  177.         reg_form($maxNameLength,$maxPassLength,$player,$password,$pass2,$email,$classchoice);
  178.     } else {
  179.         $password=md5($password);
  180.  
  181.         // Class query - Get rid of this if you don't use the classes
  182.         $query = "SELECT * from classes where name='$classchoice'";
  183.         $result = mysql_query($query) or die("Could not query classes");
  184.         $result = mysql_fetch_array($result);
  185.         $att = $result['attack'];
  186.         $def = $result['defense'];
  187.         $hp  = $result['hpoints'];
  188.         $sp  = $result['spoints'];
  189.         $cname = $result['name'];
  190.         // END CLASS QUERY
  191.  
  192.         // This inserts the data into the database. If you took out classes or
  193.         // changed stuff about the players table then make sure you have the
  194.         // correct variables and such here.
  195.         $SQL = "INSERT INTO players(name, password, email, level, exper, location, attack, defense, hpoints, maxhp, spoints, maxspoints,pclass)
  196.        VALUES ('$player','$password','$email','1','0','Crocania','$result[attack]','$result[defense]','$result[hpoints]','$result[hpoints]','$result[spoints]','$result[spoints]','$result[name]')";
  197.  
  198.         mysql_query($SQL) or die("could not register");
  199.         echo "Successfully registered!";
  200.         echo "<br><a href='./index.php'>Go back to login</a>";
  201.     }
  202.     // END ERROR HANDLER
  203.    
  204. } else {
  205.     // What happens when you first enter the page
  206.     reg_form($maxNameLength,$maxPassLength);
  207. }
  208.    
  209.    
  210. ?>
  211. </div>
  212.     </body>
  213. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement