Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Load requires
- $page_title = 'Create A Character';
- require_once('startsession.php');
- require_once('header.php');
- require_once('dbc.php');
- require_once('navmenu.php');
- // Set connect vars
- $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
- if (!isset($_SESSION['ID']))
- {
- $ready = true;
- if (isset($_COOKIE['ID']) && isset($_COOKIE['username']))
- {
- $_SESSION['ID'] = $_COOKIE['ID'];
- $_SESSION['username'] = $_COOKIE['username'];
- }
- if (isset($_POST['submit']))
- {
- $username = mysqli_real_escape_string($dbc, trim($_POST['username']));
- $password1 = mysqli_real_escape_string($dbc, trim($_POST['password1']));
- $password2 = mysqli_real_escape_string($dbc, trim($_POST['password2']));
- $email = mysqli_real_escape_string($dbc, trim($_POST['email']));
- $charname = mysqli_real_escape_string($dbc, trim($_POST['charname']));
- $race = mysqli_real_escape_string($dbc, trim($_POST['race']));
- $class = mysqli_real_escape_string($dbc, trim($_POST['class']));
- if ((!empty($username) && !empty($password1) && !empty($password2) && !empty($email) &&
- !empty($charname) && !empty($race) && !empty($class)))
- {
- // Start Username Check
- if (!preg_match('/^[a-zA-Z]+$/', $username))
- {
- $ready = false;
- echo '<p class="error">Username must contain only letters</p>';
- }
- // End Username Check
- // Start Email Check
- if (!preg_match('/[a-zA-Z0-9][a-zA-Z0-9\._\-&!?=#]*@/', $email))
- {
- $ready = false;
- echo '<p class="error">Your email address is invalid.</p>';
- }
- else
- {
- // Strip out everything but the domain from the email
- $domain = preg_replace('/^[a-zA-Z0-9][a-zA-Z0-9\._\-&!?=#]*@/','' , $email );
- // Now check if $domain is registered
- if (!checkdnsrr($domain))
- {
- echo '<p class="error">Your email address is invalid.</p>';
- $ready = false;
- }
- }
- // End Email Check
- // Start Charname Check
- if (!preg_match('/^[a-zA-Z]+$/', $charname))
- {
- $ready = false;
- echo '<p class="error">Character name must contain only letters</p>';
- }
- // End Charname Check
- // Start Password Check
- if ($password1 != $password2)
- {
- $ready = false;
- echo '<p class="error">Your passwords must match.</p>';
- }
- // End Password Check
- // Check For Duplicate Username Start
- $query = "SELECT * FROM users WHERE username = '$username'";
- $data = mysqli_query($dbc, $query);
- if (mysqli_num_rows($data) == 0)
- {
- if ($ready == true)
- {
- // INSERT student into table if no errors
- $query = "INSERT INTO users (username, password, email, charname, race, class)
- VALUES ('$username', SHA('$password1'), $email, $charname, $race, $class)";
- mysqli_query($dbc, $query);
- echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.php">log in</a>.</p>';
- mysqli_close($dbc);
- exit();
- }
- }
- else
- {
- echo '<p class="error">An account already exists for this username. Please use a different username.</p>';
- }
- // Check For Duplicate Username End
- }
- else
- {
- echo '<p class="error">Fields cannot be left blank!</p>';
- }
- }
- mysqli_close($dbc);
- ?>
- <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
- <fieldset id="container">
- <p>Please enter your information to apply.</p>
- <fieldset><legend>User Information</legend>
- <!-- Username -->
- <label for="username">Username:</label>
- <input type="text" id="username" name="username"
- value="<?php if (!empty($username)) echo $username; ?>" /><br />
- <!-- Password -->
- <label for="password1">Password:</label>
- <input type="text" id="password1" name="password1"
- value="<?php if (!empty($password1)) echo $password1; ?>"/><br />
- <label for="password2">Password (retype):</label>
- <input type="text" id="password2" name="password2"
- value="<?php if (!empty($password2)) echo $password2; ?>"/><br />
- <!-- Email -->
- <label for="email">Email:</label>
- <input type="text" id="email" name="email"
- value="<?php if (!empty($email)) echo $email; ?>"/><br />
- </fieldset>
- <fieldset><legend>Character Information</legend>
- <!-- Email -->
- <label for="charname">Character name:</label>
- <input type="text" id="charname" name="charname"
- value="<?php if (!empty($charname)) echo $charname; ?>"/><br />
- <!-- Race -->
- <label for="race">Race:</label>
- <select id="race" name="race">
- <option value="human">Human</option>
- <option value="dwarf">Dwarf</option>
- <option value="elf">Elf</option>
- </select><br />
- <!-- Class -->
- <label for="class">Class:</label>
- <select id="class" name="class">
- <option value="monk">Monk</option>
- <option value="warrior">Warrior</option>
- <option value="thief">Thief</option>
- </select><br />
- </fieldset>
- <input type="submit" id="submit" value="Register" name="submit" />
- </fieldset>
- </form>
- <?php
- }
- else
- {
- echo 'Please log out to sign up.';
- }
- ?>
- <?php
- // Insert the page footer
- require_once('footer.php');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement