Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $fname = '';
- $lname = '';
- $email = '';
- $conn = '';
- if(isset($_POST ['register']))
- {
- // Assign local variables to form data
- $fname = trim($_POST['fname']);
- $lname = trim($_POST['lname']);
- $email = trim($_POST['email']);
- $fname = stripcslashes($fname) ;
- $lname = stripcslashes($lname);
- $email = stripcslashes($email);
- if(!empty($fname and $lname and $email)){
- // Connect to db
- // Validate if the email account already exists
- $query = "SELECT email FROM tbl_users WHERE email ='$email'";
- //$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
- $result = mysqli_query($conn, $query) or die(mysqli_error($conn));
- $count = mysql_num_rows($result);
- /*
- echo $row[0];
- echo $count;
- echo $fname;
- echo $email;
- echo $lname;
- */
- // Generate random 32 character hash and assign it to a local variable.
- // Example output: f4552671f8909587cf485ea990207f3b
- $hash = md5( rand(0,1000) );
- $password = rand(1000,5000); // Generate random number between 1000 and 5000 and assign it to a local variable. // Example output: 4568
- $md5_password = md5($password) ;
- if (empty($row = mysqli_fetch_array($result)))
- {
- $to = $email; // Send email to our user
- $subject = 'Signup | Verification'; // Give the email a subject
- $message = '
- Thanks for signing up!
- Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.
- ------------------------
- Username: '.$email.'
- Temporary Password: '.$password.'
- ------------------------
- Please click this link to activate your account:
- http://localhost/gurukul/user/verify.php?email='.$email.'&hash='.$hash.'
- '; // Activation link -Concatenate email and md5 hash - direct to verify.php to validate the link
- // Our message above including the link
- $headers = 'From:noreply@yourwebsite.com' . "rn"; // Set from headers
- $usertype = "Stu_Account";
- if(mail($to, $subject, $message, $headers)){// Send our email --- and if email sent successfully then insert data into db
- // Insert new user data into users table
- $query = "INSERT INTO tbl_users(f_name,l_name,email,hash,temp_password,user_type) VALUES ('$fname','$lname','$email','$hash','$md5_password','$usertype') ";
- $result = mysqli_query($conn, $query) or die(mysqli_error($conn));
- mysqli_close($conn);
- // echo $md5_password;
- // echo 'check mail';
- // echo $password;
- ?>
- <script type="text/javascript">
- // history.back();
- window.location.replace("index.php");
- alert("Your account is successfully created! n An email is sent on your account. Please check your email shortly to activate your account. ");
- </script>
- <?php
- } else{
- ?>
- <script type="text/javascript">
- history.back();
- alert("Email Could Not be Sent. nnYour Account is Not Created, Try Again Shortly. n nPlease Contact Administator if the Issue Persists. ");
- </script>
- <?php
- }
- }else{
- // The Email Account is Already Registered';
- ?>
- <script type="text/javascript">
- history.back();
- alert("This email id is already registered.nn Please go to home page to login or create a new account with another email id.");
- </script>
- <?php
- }
- }else{
- ?>
- <script type="text/javascript">
- history.back();
- alert("Some data is missing, please enter all the details..");
- </script>
- <?php
- }
- }
- ?>
Add Comment
Please, Sign In to add comment