Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ## Displaying form is no form has already been submitted
- if(!isset($_POST['submit'])) {
- ## Creating a 'goto' point for later use
- form: {
- ?>
- <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
- Username: <input type='text' name='username' /><br />
- Password: <input type='text' name='password' /><br />
- Password Confirmation: <input type='text' name='passwordc' /><br />
- Email: <input type='text' name='email' /><br />
- <input type='submit' name='submit' value='Sign Up' />
- </form>
- <?php
- }
- }
- ## Processing if a form has been submitted
- else {
- ## A little security measure
- $username = mysql_real_escape_string($_POST['username']);
- $username = htmlentities($username);
- $password = mysql_real_escape_string($_POST['password']);
- $passwordc = mysql_real_escape_string($_POST['passwordc']);
- $email = mysql_real_escape_string($_POST['email']);
- ## Connecting to the database, you need to fill in with your information
- $con = mysql_connect('localhost', 'username', 'password');
- mysql_select_db('dbname', $con);
- ## Checking to see if the username has been taken
- $check = sprintf("SELECT * FROM users WHERE Username='%s'", $username);
- $check_ = mysql_query($check);
- $check__count = mysql_num_rows($check_);
- if($check__count > 0) { echo 'We already have a user signed up with that username. <br /><br />'; goto form; }
- ## Checking to see if passwords match
- if($password != $passwordc) { echo 'Your two passwords do not match. <br /><br />'; goto form; }
- ## Checking length of password
- if(strlen($password) < 4) { echo 'Your password is too short. Must be more than 4 characters. <br /><br />'; goto form; }
- ## Checking to see if the email is taken
- $check = sprintf("SELECT * FROM users WHERE Email='%s'", $email);
- $check_ = mysql_query($check);
- $check__count = mysql_num_rows($check_);
- if($check__count > 0) { echo 'We already have a user signed up with that email. <br /><br />'; goto form; }
- ## Inserting information to the database, with the 'Type' set to 0, which means the account is not activated. You'll need to change it to 1 in order to activate the account
- $query = "INSERT INTO users (Username, Password, Email, Type) VALUES ('$username', '$password', '$email', '0')";
- mysql_query($query);
- ## Sending a mail to you
- $to = 'youremail@yourdomain.com';
- $subject = 'User in need of activation';
- $message = 'A user has just registered with the username: ' . $username . '. He is need of activation.';
- mail($to, $subject, $message);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement