Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once("global.php");
- $message = '';
- if($_SERVER['REQUEST_METHOD'] == "POST") {
- $username = $_POST['username'];
- $firstname = $_POST['firstname'];
- $secondname = $_POST['lastname'];
- $email = $_POST['email'];
- $password = $_POST['password'];
- $password2 = $_POST['password2'];
- if ((!$username) || (!$firstname) || (!$lastname) || (!$email) || (!$password) || (!$password2)){
- $message = 'Please fill in all fields in the form below';
- }else{
- if($password != $password2) {
- $message = 'Your passwords do not match.';
- }else {
- $username = preg_replace("#[^0-9a-z]#i", "", $username);
- $firstname = preg_replace("#[^0-9a-z]#i", "", $firstname);
- $lastname = preg_replace("#[^0-9a-z]#i", "", $lastname);
- $password = sha1($password);
- $email = mysql_real_escape_string($email);
- $user_query = mysql_query("SELECT username FROM members WHERE username='$username' LIMIT 1") or die ("Could not check username");
- $count_username = mysql_num_rows($user_query);
- $email_query = mysql_query("SELECT email FROM members WHERE email='$email' LIMIT 1") or die ("Could not check email");
- $count_email = mysql_num_rows($email_query);
- if($count_username > 0){
- $message = 'Your username is already in use';
- }else if($count_email > 0) {
- $message = 'Your email is already in use.';
- }else {
- $ip_address = $_SERVER['REMOTE_ADDR'];
- $query = mysql_query("INSERT INTO members (username, firstname, lastname, email, password, ip_address, sign_up_date) VALUES ('$username, $firstname, $lastname, $email, $password, ip_address, sign_up_date now())')") or die ("Could not insert data");
- $member_id = mysql_insert_id();
- mkdir("users/$member_id", 0755);
- $message = 'You succesfully registered.';
- }
- }
- }
- }
- ?>
- <html DOCTYPE>
- <html>
- <head>
- <title>Welcome to our website!</title>
- <!-- CSS Imports -->
- <link rel="stylesheet" href="css/style.css" />
- </head>
- <body>
- <!-- Content -->
- <div class="container center">
- <h1>Register to my website</h1>
- <p><?=$message;?><p>
- <form action="register.php" method="post"
- <input type="text" name="username" placeholder="Username" /></br>
- <input type="text" name="firstname" placeholder="First Name" /></br>
- <input type="text" name="lastname" placeholder="Last Name" /></br>
- <input type="text" name="email" placeholder="Email" /></br>
- <input type="password" name="password" placeholder="Password" /></br>
- <input type="password" name="password2" placeholder="Validate Password" /></br>
- <input type="submit" value="Register" />
- </form>
- </div>
- <!-- JS Imports -->
- </body>
- </html>
Add Comment
Please, Sign In to add comment