PHP Register Login Script with Email Verification

Webslesson

PHP, MySql, Jquery, AngularJS, Ajax, Codeigniter, Laravel Tutorial

Monday, 4 December 2017

PHP Registration Script with Email Confirmation

In this post, We have start learning how can we send user activation email after completing user registration. Because if you have created an account on any website and have you verify you email by click through a verification link send by website for activate or verify email which you have enter email at the time of registration. So we have make this post to learn how can you build an email verification script step by step.

This is email verify PHP script in which you allows you to verify your email address at the time of registration. This email verification script used at the time of new registration or this script also required when in your site has rss subscription, then use has enter email for subscribe rss feed. So email must be original and reduce spam. So At that time we want to verify email address by sending verification link to that email address.

Here we have use simple PHP registration example to verify email address by sending email activation link to their account and by clicking on that link email will be verified. For make this script we have use PHP PDO script with Mysql Database and for sending email we have use PHPMailer Library. In this script user can register into site by entering proper email and after register with email address, then they will received email verification link into their email address. So if email will be proper then he will received email verification link. If user not verified their email address then he cannot login into site. For access website user want to verify their email address. This script helpful to reduce spam registration into website. For email verification user has go to email account and in his email address he will received email verification link with password. So user can verify email by clicking on that link. After email verification user can also received password in his email also. After this email verification user can login into system. This way we can verify email address for reduce span registration by using PHP PDO with Mysql Database and PHPMailer Library.

Читайте также:  Getting started with python language

Source Code

database_connection.php

register.php

  $message = ''; if(isset($_POST["register"])) < $query = " SELECT * FROM register_user WHERE user_email = :user_email "; $statement = $connect->prepare($query); $statement->execute( array( ':user_email' => $_POST['user_email'] ) ); $no_of_row = $statement->rowCount(); if($no_of_row > 0) < $message = ''; > else < $user_password = rand(100000,999999); $user_encrypted_password = password_hash($user_password, PASSWORD_DEFAULT); $user_activation_code = md5(rand()); $insert_query = " INSERT INTO register_user (user_name, user_email, user_password, user_activation_code, user_email_status) VALUES (:user_name, :user_email, :user_password, :user_activation_code, :user_email_status) "; $statement = $connect->prepare($insert_query); $statement->execute( array( ':user_name' => $_POST['user_name'], ':user_email' => $_POST['user_email'], ':user_password' => $user_encrypted_password, ':user_activation_code' => $user_activation_code, ':user_email_status' => 'not verified' ) ); $result = $statement->fetchAll(); if(isset($result)) < $base_url = "http://localhost/tutorial/email-address-verification-script-using-php/"; $mail_body = " 

Hi ".$_POST['user_name'].",

Thanks for Registration. Your password is ".$user_password.", This password will work only after your email verification.

Please Open this link to verified your email address - ".$base_url."email_verification.php?activation_code=".$user_activation_code."

Best Regards,
Webslesson

"; require 'class/class.phpmailer.php'; $mail = new PHPMailer; $mail->IsSMTP(); //Sets Mailer to send message using SMTP $mail->Host = 'smtpout.secureserver.net'; //Sets the SMTP hosts of your Email hosting, this for Godaddy $mail->Port = '80'; //Sets the default SMTP server port $mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables $mail->Username = 'xxxxxxxx'; //Sets SMTP username $mail->Password = 'xxxxxxxx'; //Sets SMTP password $mail->SMTPSecure = ''; //Sets connection prefix. Options are "", "ssl" or "tls" $mail->From = 'info@webslesson.info'; //Sets the From email address for the message $mail->FromName = 'Webslesson'; //Sets the From name of the message $mail->AddAddress($_POST['user_email'], $_POST['user_name']); //Adds a "To" address $mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters $mail->IsHTML(true); //Sets message type to HTML $mail->Subject = 'Email Verification'; //Sets the Subject of the message $mail->Body = $mail_body; //An HTML or plain text message body if($mail->Send()) //Send an Email. Return true on success or false on error < $message = ''; > > > > ?>

PHP Register Login Script with Email Verification


Register

Login

email_verification.php

 prepare($query); $statement->execute( array( ':user_activation_code' => $_GET['activation_code'] ) ); $no_of_row = $statement->rowCount(); if($no_of_row > 0) < $result = $statement->fetchAll(); foreach($result as $row) < if($row['user_email_status'] == 'not verified') < $update_query = " UPDATE register_user SET user_email_status = 'verified' WHERE register_user_id = '".$row['register_user_id']."' "; $statement = $connect->prepare($update_query); $statement->execute(); $sub_result = $statement->fetchAll(); if(isset($sub_result)) < $message = ''; > > else < $message = ''; > > > else < $message = ''; > > ?>        

PHP Register Login Script with Email Verification

login.php

  $message = ''; if(isset($_POST["login"])) < $query = " SELECT * FROM register_user WHERE user_email = :user_email "; $statement = $connect->prepare($query); $statement->execute( array( 'user_email' => $_POST["user_email"] ) ); $count = $statement->rowCount(); if($count > 0) < $result = $statement->fetchAll(); foreach($result as $row) < if($row['user_email_status'] == 'verified') < if(password_verify($_POST["user_password"], $row["user_password"])) < $_SESSION['user_id'] = $row['register_user_id']; header("location:index.php"); >else < $message = ""; > > else < $message = ""; > > > else < $message = ""; > > ?>        

PHP Register Login Script with Email Verification


Login

Register

logout.php

Database

 -- -- Database: `testing` -- -- -------------------------------------------------------- -- -- Table structure for table `register_user` -- CREATE TABLE IF NOT EXISTS `register_user` ( `register_user_id` int(11) NOT NULL, `user_name` varchar(250) NOT NULL, `user_email` varchar(250) NOT NULL, `user_password` varchar(250) NOT NULL, `user_activation_code` varchar(250) NOT NULL, `user_email_status` enum('not verified','verified') NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; -- -- Dumping data for table `register_user` -- INSERT INTO `register_user` (`register_user_id`, `user_name`, `user_email`, `user_password`, `user_activation_code`, `user_email_status`) VALUES (1, 'John Smith', 'web-tutorial@programmer.net', '$2y$10$vdMwAmoRJfep8Vl4BI0QDOXArOCTOMbFs6Ja15qq3NEkPUBBtffD2', 'c74c4bf0dad9cbae3d80faa054b7d8ca', 'verified'); -- -- Indexes for dumped tables -- -- -- Indexes for table `register_user` -- ALTER TABLE `register_user` ADD PRIMARY KEY (`register_user_id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `register_user` -- ALTER TABLE `register_user` MODIFY `register_user_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2; 

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Activate user accounts before they can log in

Horttcore/confirm-user-registration

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Confirm User Registration

Admins have to confirm each user registration. A notification will be send when the account gets approved.

  • Copy the confirm-user-registration.php into your plugin directory and activate the plugin.
  • Go to ´Users > Confirm User Registration > Settings´ for further editing
  • Go to the Confirm User Registration menu in the user tab.
  • Authenticate Users : Activate user accounts
  • Block Users : Deactivate user accounts
  • Option : Change some settings

Frequently Asked Questions

Will it create any new database tables?

No, it doesnt create any new tables. The Plugin uses user meta and options table

Is there any language file?

Yes, its fully translateable. English, german, italian and serbo-croatian are included.

Screenshot of the auth/block users tab

Screenshot of the settings tab

Screenshot of login error

  • Added action: send_user_authentication ; Notification informations as parameters
  • Added action: confirm-user-registration-error ; Authentication error
  • Enhancement: confirm-user-registration-notification-header filter has user as arguement
  • Enhancement: confirm-user-registration-notification-subject filter has user as arguement
  • Enhancement: confirm-user-registration-notification-message filter has user as arguement
  • Translation: Italian language by ostroso
  • Bugfix: Usernames with an @ in it will be confirmed correctly
  • Bugfix: Bulk delete checks for delete_users capability
  • Bugfix: Missing translation for user roles
  • Added action: confirm-user-registration-auth-user ; User ID as parameter
  • Added action: confirm-user-registration-block-user ; User ID as parameter
  • Added action: confirm-user-registration-options ; for extending the plugin settings
  • Added filter: confirm-user-registration-error-message ; Display different error message
  • Added filter: confirm-user-registration-save-option ; Save custom options
  • Added filter: confirm-user-registration-notification-header ; Change notification e-mail header
  • Added filter: confirm-user-registration-notification-subject ; Change notification e-mail subject
  • Added filter: confirm-user-registration-notification-message ; Change notification e-mail message
  • Fix: Translation error for de_DE
  • Fix: No javascript loop when no user is selected
  • Enhancement: Prevent to block your own account
  • Complete new interface so it looks like a normal WordPress Backend Site.
  • Added authenticate accounts panel.
  • Added block accounts panel.
  • Added an options panel.
  • User can edit the confirmation E-mail adress.
  • User can edit the confirmation E-mail subject.
  • User can edit the confirmation E-mail message.

Источник

Оцените статью