Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // include common.inc.php
- include 'core/common.inc.php';
- // show header / add title
- showHeader('Registration');
- // protect page from users already logged in
- protect();
- // turn off error_reporting
- error_reporting(0);
- ?>
- <center>
- <form enctype="multipart/form-data" action="" method="post" class="register_module">
- <h2 style="text-align:left;font-family:'Roboto',sans-serif;">Account Credentials<span style="font-size:12px;font-weight:400;"> (required)</span></h2>
- <div class="account_credentials">
- <input class="register_module protect_from_spaces" type="text" name="username" placeholder="choose a username*" maxlength="30" required><br />
- <input class="register_module protect_from_spaces" type="email" name="email" placeholder="email address*" required><br />
- <div class="row_inline">
- <input class="register_module input protect_from_spaces" type="password" name="password" placeholder="password*" maxlength="18" required>
- <input class="register_module input protect_from_spaces" type="password" name="cpassword" placeholder="confirm password*" maxlength="18" required><br />
- </div>
- </div>
- <br />
- <!-- here add user details section (name, avatar, birthday, etc...) -->
- <h2 style="text-align:left;font-family:'Roboto',sans-serif;">Account Details<span style="font-size:12px;font-weight:400;"> (optional)</span></h2>
- <br />
- <div class="account_details">
- <p style="text-align:left;font-family:'Roboto',sans-serif;font-weight:400;">Name:<span style="font-size:12px;font-weight:400;"> (required)</span></p>
- <input class="register_module_short protect_from_spaces" style="margin-right:1%;" type="text" name="first_name" placeholder="first name*" required />
- <input class="register_module_short protect_from_spaces" type="text" name="last_name" placeholder="last name" />
- <p style="text-align:left;font-family:'Roboto',sans-serif;font-weight:400;">Birthday:</p>
- <input style="margin-top:-10px;" class="register_module protect_from_spaces" type="date" name="birthday" />
- <p style="text-align:left;font-family:'Roboto',sans-serif;font-weight:400;">Social Link(s):</p>
- <input class="register_module protect_from_spaces" type="text" style="margin-top:-10px;" type="url" name="steam_profile" placeholder="steam profile (http://www.steamcommunity.com/id/lowheartrate/)" />
- <input class="register_module protect_from_spaces" type="text" name="twitter_profile" placeholder="twitter profile (https://twitter.com/lowheartrate)" />
- <input class="register_module protect_from_spaces" type="text" name="facebook_profile" placeholder="facebook profile (https://www.facebook.com/officiallowheartrate)" />
- <input class="register_module protect_from_spaces" type="text" name="instagram_profile" placeholder="instagram profile (https://instagram.com/lowheartrate)" />
- <!-- image upload for avatar... -->
- <div class="image_uploader">
- <h2 style="text-align:left;font-family:'Roboto',sans-serif;">✌ Avatar Uploader</h2><br />
- <p style="margin-top:-20px;font-size:12px;text-align:left;">Select image to upload:</p>
- <div style="text-align:left;font-size:12px;margin-top:-5px;margin-bottom:25px;">
- <input type="file" name="avatar" class="" />
- </div>
- </div>
- </div>
- <!-- check errors in registration -->
- <?php checkRegisterErrors(); ?>
- <br />
- <p class="pull-left" style="max-width:50%;">by signing up, you agree to our <a href="#">terms</a> and that you have read our <a href="#">privacy policy</a> and <a href="#">content policy</a>.</p>
- <div class="g-recaptcha pull-right" data-sitekey="6Levrg4TAAAAAN-pL6Xl2tndj3ZDn5nJ3PRUhMV-"></div><br />
- <br />
- <button type="submit" name="submit_registration" class="btn-register" style="margin-top:10px;">sign up</button>
- </form>
- </center>
- <?php
- // Generate Random String function taken from
- // http://stackoverflow.com/questions/4356289/php-random-string-generator
- function generateRandomString($length) {
- $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $charactersLength = strlen($characters);
- $randomString = '';
- for($i = 0; $i < $length; $i++) {
- $randomString .= $characters[rand(0, $charactersLength - 1)];
- }
- return $randomString;
- }
- // checks registration errors...
- function checkRegisterErrors() {
- $username = $_POST['username'];
- // check to see if the form was submitted
- if($_SERVER['REQUEST_METHOD'] == 'POST') {
- require 'findConflict.php';
- $username = $_POST['username'];
- $password = $_POST['password'];
- $cpassword = $_POST['cpassword'];
- $email = $_POST['email'];
- $hash = password_hash($password, PASSWORD_DEFAULT);
- $query = dbConnect()->prepare("SELECT email, username FROM users WHERE username = :username OR email = :email");
- $query->bindParam(':username', $username);
- $query->bindParam(':email', $email);
- $query->execute();
- $conflictingItems = [];
- while ( $result = $query->fetch( PDO::FETCH_ASSOC ) ) {
- $conflictingItems[] = $result;
- }
- // for checking checkGoogleCaptcha() function!!
- require_once 'core/recaptchalib.php';
- if(isset($_POST['g-recaptcha-response']))
- $captcha = $_POST['g-recaptcha-response'];
- $response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6Levrg4TAAAAAFmjcgKW8kDakmXTiBhmiCnUMchD&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
- if ( count ($conflictingItems) == 1 ) {
- switch ( getConflict($conflictingItems, $username, $email) ) {
- case 1:
- // username conflict
- echo "<p class='error'>username taken</p>";
- break;
- case 2:
- // Email conflict
- echo "<p class='error'>email already in use</p>";
- break;
- case 3:
- // email & username conflict
- echo '<p class="error">username & email in use</p>';
- break;
- }
- } elseif ( count($conflictingItems) == 2 ) {
- echo 'username & email already in use';
- // check if passwords match!
- } elseif ($password != $cpassword) {
- echo '<p class="error">passwords do not match</p>';
- // make sure password is between 8 - 16 characters
- } elseif (strlen($password) < 8 OR strlen($password) > 16) {
- echo '<p class="error">password must be between 8 & 16 characters</p>';
- // checks to make sure google recaptcha was posted!
- } elseif (!$captcha) {
- echo '<p class="error">please complete the captcha</p>';
- } elseif($response['success'] == false) {
- echo '<p class="error">you are a robot</p>';
- } else {
- // require config.php to get maximum file size --> $maximum_avatar_file_size = '125000';
- // to get avatars directory --> $avatars_directory = 'includes/uploads/avatars';
- require 'core/config.php';
- // need for file upload query & query to insert fields into database..
- $activation_id = uniqid(true);
- // file upload stuff... ONLY NEEDED FOR TESTING PURPOSES!
- // var_dump($_FILES);
- // move uploaded file to directory (includes/uploads/avatar)
- $upload_directory = $avatars_directory; // the directory you want to store the avatars in...
- // sets $image & gets image type, name, tmp_name
- $image = $_FILES['avatar']; // create and append new varaible to $_FILES['avatar'] so that we don't have to manually type in the full variable for it.
- // get image temporary name...
- $image_tmp_name = $image['tmp_name']; // get the tmp file
- // get image size...
- $image = getimagesize($image['tmp_name']); // get the image size of tmp file
- $image_mime = $image['mime']; // create and append the mime array to $image_mime
- // List the mime types you want to allow in your upload system...
- $valid_image_mime = array('image/jpeg', 'image/jpg', 'image/png', 'image/gif');
- // generate random string with generateRandomString() function...
- $random = generateRandomString(16);
- $ext = '.jpg'; // file extension we want it to end up being once its uploaded.
- $file_name = $random . $ext; // Append the generated string along with the desired extension to the new file name.
- // Check to see if the mime type from the tmp file is in our array above...
- if(in_array($image_mime, $valid_image_mime)) {
- // So we are good to go. The mime type is listed in our array
- // Check to see moving the tmp file to our desired directory works.
- if(move_uploaded_file($image_tmp_name, $upload_directory . '/' . $file_name )) {
- // since the file has been uploaded, we can now update our old avatar record
- // and set it to the current one.
- $sql = "UPDATE users SET avatar = :avatar WHERE username = :username";
- $prepare = dbConnect()->prepare($sql);
- $parameters = array(':avatar' => $file_name, ':username' => $username);
- $prepare->execute($parameters);
- // check to see if the query executed
- if ($prepare->rowCount()) {
- // print('Good');
- header('Location: ' . $_SERVER['REQUEST_URI']);
- } else {
- // print('Bad Upload');
- header('Location: ' . $_SERVER['REQUEST_URI']);
- }
- } else {
- // print('Bad');
- header('Location: ' . $_SERVER['REQUEST_URI']);
- }
- }
- // query to insert fields into database...
- //$activation_id = uniqid(true);
- $query = dbConnect()->prepare("INSERT INTO users (username, password, email, activated, activation_id) VALUES (:username, :password, :email, :activated, :activation_id)");
- $query->bindParam(':username', $username);
- $query->bindParam(':email', $email);
- $query->bindParam(':password', $hash);
- $query->bindValue(':activated', "0");
- $query->bindValue(':activation_id', $activation_id);
- $query->execute();
- // set variables for optional fields...
- $firstName = $_POST['first_name'];
- $lastName = $_POST['last_name'];
- $birthday = $_POST['birthday'];
- $steam_profile = $_POST['steam_profile'];
- $twitter_profile = $_POST['twitter_profile'];
- $facebook_profile = $_POST['facebook_profile'];
- $instagram_profile = $_POST['instagram_profile'];
- // update user_details database
- $query2 = dbConnect()->prepare("INSERT INTO user_details (first_name, last_name, birthday, steam_profile, twitter_profile, facebook_profile, instagram_profile) VALUES (:firstName, :lastName, :birthday, :steam, :twitter, :facebook, :instagram)");
- $query2->bindParam(':firstName', $firstName);
- $query2->bindParam(':lastName', $lastName);
- $query2->bindParam(':birthday', $birthday);
- $query2->bindParam(':steam', $steam_profile);
- $query2->bindParam(':twitter', $twitter_profile);
- $query2->bindParam(':facebook', $facebook_profile);
- $query2->bindParam(':instagram', $instagram_profile);
- $query2->execute();
- // query to add image name to database to echo later on...
- /*
- $add_image_to_database = dbConnect()->prepare("INSERT INTO users (avatar) VALUES (:avatar)");
- $add_image_to_database->bindParam(':avatar', $file_name);
- $add_image_to_database->execute();
- */
- // send email verification
- require 'core/config.php';
- $subject = $url . 'Registration Confirmation';
- $link = 'http://' . $url. "/activate.php?activation_id=" . $activation_id;
- $message = 'Thanks for registering with us! Please verify your account at' . $link . ' so you can login.';
- $headers = 'From: ' .$contact_email;
- mail($email/* <-- Who its being sent to */, $subject, $message, $headers);
- echo '<p class="info">registration successful, please verify email before logging in.</p>';
- header('refresh:5;url=index.php');
- echo '<p class="info">if you are not redirected, try to <a href="index.php">refresh</a> your page.</p>';
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment