close ad
 
Important WebAssist Announcement
open ad
View Menu

Web development tutorial

Double opt in registration

Tutorial created by Ray Borduin, WebAssist

Categories: Data Bridge

rating

This tutorial walks you through the steps to create a double opt in registration system, where users have to verify their email address after they register. You can use Data Bridge to follow these steps in Dreamweaver.

arrow downWhat you'll need to start

  1. A dynamic site set up within Dreamweaver
  2. Web Browser (Chrome, Firefox, Internet Explorer, etc.)
  3. Dreamweaver CS3 or later
  4. Data Bridge installed and activated in Dreamweaver

arrow downCreate your database

The very first step in this whole process will br creating a database for your user information. You don't need to create any tables within the database, as Data Bridge will create all needed tables, and add the information as users register for your site.

For more information regarding the creation of a database within your specific website environment, please contact your hosting provider.

arrow downCreate your pages

We're going to create the pages needed for users to register, login, logout, and so on. These will be automatically created by SecurityAssist, as will the tables in your database.

  1. Open a php page in your site.
  2. In the menu bar, click WebAssist > SecurityAssist > Create Security Pages.
  3. In the Select Preset section, change the Preset drop down list to Simple Registration SP.
  4. In the Database Settings section, click the Define button.
  5. Click New.
  6. Click MySQL Connection.
  7. Enter the correct information for the database you created for the tutorial and ensure a connection can be made.
  8. Select the newly created connection from the Connection drop down list in the Database Settings section.
  9. Click OK.
    After the pages are created by the SecurityAssist wizard, the Access Pages Manager will pop up.
  10. Click OK.



Once the wizard has completed it's dark task, you are ready to move on to the next step.

arrow downCreate the success page

At this point we're going to need to create additional pages for the double opt in registration system to work. The first of these pages is a simple success page.

  1. Click File > New in the menu bar.
  2. Create a blank PHP page named register-confirm.php .
  3. In the body of the page, enter the following text. Note that this is just for this tutorial. You may want to use something more personalized to your site.
    Please check the inbox of the email address you registered with, where you can verify your email. Once you have done that, you can log in.

  4. Change the "log in" text in the message to be a link to the login page created by the SecurityAssist Wizard.
  5. Save the page.



Now we have a rudimentary success page that will be shown once the registration form is submitted.

arrow downCreate the verification page

The second of these pages is the verification page. This is the page the user will see when they click the verification link within their registration email.

  1. Click File > New in the menu bar.
  2. Create a blank PHP page named user-confirm.php .
  3. In the body of the page, enter the following text. Note that this is just for this tutorial. You may want to use something more personalized to your site.
  4. Thank you for verifying your email address. You may now access restricted content.
    Your verification link has expired. Visit your profile page to send a new link.

  5. Change the "access restricted content" text in the message to be a link to the login page created by the SecurityAssist Wizard.
  6. Change the "profile page" text in the message to be a link to the userupdate.php page created by the SecurityAssist Wizard.
  7. Save the page.

arrow downCreate the registration email

Now we need to create the email that will be sent to the user letting them know they need to confirm their registration, and the information they need to actually go about confirming it.

  1. Open the registration.php page created by SecurityAssist.
  2. In the menu bar, click WebAssist > Create Email Message.
  3. Click the browse button next to the Go To Page field.
  4. Select the register-confirm.php that we created earlier.
  5. Click OK.
  6. In the From field, enter whatever email you wish the registration emails to come from.
  7. Next to the To field, click the lightning bolt.
  8. Expand the Registration_Basic_Default list in the bindings dialog.
  9. Select the Registration_group_Email binding.
  10. Click OK.
  11. In the Subject field, enter "Please verify your email address". This can be customized for your particular site.
  12. Click Finish.
  13. Save the page.


Basic email functionality has been added to the registration form that will send an email when the form has been submitted. A new page has also been created for the body of the email called Blank.php.

arrow downAdd database fields

Next up, we need to add two additional fields to the database. One to hold a random string to send the user in their verification URL so we know exactly which user is verifying their registration, as well as a field to determine if the user has verified their email or not.

  1. In your specific database manager, open the database created for this tutorial.
  2. Open the users table.
  3. Insert two additional fields in the table.
  4. Name the first field randomString.
  5. Change the Type of the field to TEXT.
  6. Name the second forms emailVerified.
  7. Change the Type to INT.
  8. Set the Default Value to 0.
    This indicated the user is not verified by default.
  9. Save the new fields.

arrow downCreate the random string

Since we've created a database field to hold the random string for the verification URL, we're going to need to create the random string itself.

  1. Return to the registration.php file we were using earlier.
  2. Click Window > Bindings to open the Bindings panel, if it isn't open already.
  3. Click the Plus ( ) button.
  4. Select WebAssist > SecurityAssist > Random Password.
  5. Toggle to the Server Behaviors panel.
  6. Click the Plus ( ) button.
  7. Select WebAssist > Cookies > Set Session Value.
  8. Set the Trigger to before page load.
  9. Change the Name to rpw.
  10. Next to the Value field, click the lightning bolt.
  11. Expand the SecurityAssist list in the bindings dialog.
  12. Select the Random Password binding.
    This will open the Generate Random Password dialog. Here we can set just how random this string will be. For this tutorial we'll use the default settings.

  13. Click OK.
  14. Click OK on the bindings dialog.
  15. Click OK on the Set Session Value dialog.
  16. Save the page.

arrow downAdd the string to the database

Since we have this fancy random string all created, we need to insert it into the database so we know which string is for which user.

  1. Click Window > Server Behaviors to open the Server Behaviors panel, if it isn't open already.
  2. Find the Server Behavior called Insert Record (users).
  3. Double click the Server Behavior to open it.
  4. Click the Bindings Tab.
  5. Click randomString from the Column column.
  6. Next to the Value field, click the lightning bolt.
  7. Expand the Session list in the server entity dialog.
  8. Select rpw.
  9. Click OK.
  10. Click the General Tab.
  11. Clear the Go to (optionall) field in the After Insert section.
    Clearing this value allows the trigger we set earlier in Universal Email to fire instead of this one.
  12. Uncheck the Pass original querystring checkbox.
  13. Click OK.
  14. Save the page.



After all this work, the random string that we are creating will be inserted into the database when a user registers.

arrow downAdd email verification links

We're going to edit the email set to the users to show the verification URL they can click to verify their email.

For this URL, we are going to pass in the random string, and for the sake of security, we're going to pass in the email as well.

  1. Open the Blank.php email page that was created earlier.
    The email body can be fully customized by you based on your site and application. The only real required text is the verification URL. For the sake of this blessed tutorial, we're going to do basic edits only to the sections we need.

  2. Change the Additional Notes header to say "Verify Email".
  3. Clear the email body text.
  4. In the Bindings Panel, click the Plus ( ).
  5. Select Form Data.
  6. Next to the Form page field, click the browse button.
  7. Select the registration.php page.
  8. Set your cursor in the email body area.
  9. Enter the full URL the user will confirm their email address on. This will be the user-confirm.php page we created earlier (Example: http://localhost/user-confirm.php).
  10. After the URL, add the following text:
    ?id=

  11. After the ?id=, drag the SecurityAssist_UserID binding from the Session list in the Bindings panel.
  12. After the binding, add the following text:
    &randomString=

  13. After the &randomString=, drag the rpw binding from the Session list in the Bindings panel.
  14. After the bindings, add the following text:
    &email=

  15. After the ?email=, drag the Registration_group_Email binding from the Registration_Basic_Default list that we created earlier in the Bindings panel.
  16. Copy the full URL URL variables in Code View.
  17. Clear the URL from the email's body area.
  18. Enter the text, "Click here to verify your email address", or whatever text you would like.
  19. Make the text a link.
  20. Paste in the URL URL variables that we just copied.
  21. Save the page.



Sometimes the & in the URL variables will be changed to & in the code view for the URL. Make sure to change the & to just &.



Your email body%u2026 is beautiful. Now when a user registers, their registration email will have the link they need to click to verify their account.

arrow downConfigure the confirm page

Now we need to add functionality to the confirm page that will allow it to read the URL variables, and update the account accordingly.

Create the recordset

  1. Open the user-confirm.php page.
  2. In the Bindings panel, click Plus ( ).
  3. Select Recordset.
  4. Name the recordset rsVerify.
  5. Make sure the Connection is correct.
  6. Make sure the users table is selected.
  7. Change the filter to UserID.
  8. Click the Advanced button.
  9. Select colname in the Variables list.
  10. Click the Edit button.
  11. Change the runtime value from
    $_GET['UserID']

    to
    $_GET['id']

  12. Click OK.
  13. In the Database items list, Expand the Tables list.
  14. Expand the users list.
  15. Select randomString.
  16. Click the WHERE button.
    This adds randomString to the WHERE clause of the SQL query.

  17. After users.randomString in the SQL query, type in the following text:
    = paramrandomString

  18. Click the Plus ( ) next to the variables list.
  19. Set the name to paramrandomString.
  20. Set the type to Text.
  21. Set the Default value to -1.
  22. Set the Runtime value to
    $_GET['randomString']

  23. Click OK.
  24. In the Database items list, Expand the Tables list.
  25. Expand the users list.
  26. Select UserEmail.
  27. Click the WHERE button.
  28. After users.UserEmail in the SQL query, type in the following text:
    = paramemail

  29. Click the Plus ( ) next to the variables list.
  30. Set the name to paramemail
  31. Set the type to Text.
  32. Set the Default value to -1.
  33. Set the Runtime value to
    $_GET['email']

  34. Click OK.
  35. At the end of the SQL query, add the following code:
    AND users.randomString <> '0'

  36. Click OK.



Create the update verified functionality

  1. In the Bindings panel, click Plus ( ).
  2. Select URL Variable.
  3. Set id as the Name.
  4. Click OK.
  5. Once again, in the Bindings panel, click Plus ( ).
  6. Select URL Variable.
  7. This time, set email as the Name.
  8. Click OK.
  9. Go to the Server Behaviors panel.
  10. Click Plus ( ).
  11. Select WebAssist > DataAssist > Update > Update Single Record.
  12. For the Trigger field, select: Recordset rsVerify is not Empty
  13. Verify the correct Connection is selected.
  14. Verify the users table is selected.
  15. For the Value field, click the lightning bolt.
  16. Expand the Recordset (rsVerify) list.
  17. Select UserID.
  18. Click OK.
  19. Switch to the Bindings tab.
  20. Select the emailVerified column from the Column list.
  21. Change the Value to 1.
  22. Click OK.



Create the expire used random string functionality

  1. Go to the Server Behaviors panel.
  2. Click Plus ( ).
  3. Select WebAssist > DataAssist > Update > Update Single Record.
  4. Verify the correct Connection is selected.
  5. Verify the users table is selected.
  6. For the Key Column field, select UserEmail.
  7. For the Value field, click the lightning bolt.
  8. Expand the URL list.
  9. Select email.
  10. Click OK.
  11. Switch to the Bindings tab.
  12. Select the randomString column from the Column list.
  13. Change the Value to 0.
  14. Click OK.



Show the correct message for verification success/ failure

  1. Select the "Thank you for verifying your email address. You may now access restricted content." text.
  2. In the Server Behaviors panel, click Plus ( ).
  3. Select Show Region > Show if Recordset is Not Empty.
  4. Verify the rsVerify Recordset is selected.
  5. Click OK.
  6. Select the "Your verification link has expired. Visit your profile page to send a new link." text.
  7. In the Server Behaviors panel, click Plus ( ).
  8. Select Show Region > Show if Recordset is Empty.
  9. Verify the rsVerify Recordset is selected.
  10. Click OK.



Reset the user's session variable to verified status

  1. In the Server Behaviors panel, click Plus ( ).
  2. Select WebAssist > Cookies > Set Session Value.
  3. Change the Trigger to Recordset: rsVerify is not empty.
  4. Make sure the Name is set to emailVerified.
  5. Set the Value to 1.
  6. Click OK.
  7. Save the page.



Now you have a working verification page that will not only update the values in the database to show the user has verified their email, it also sets the session to show this change has also taken place.

arrow downStore verified status on login

Here we are, getting so close to completion. I hope you're sticking with us, because this bit is the absolutely most thrilling thing you will ever do in your life: updating the login Server Behaviors to store verified status on login!!!!

I can only imagine your excitement as you ready yourself for this incredible task.

  1. Open the login.php page.
  2. In the Server Behaviors panel, open the first SecurityAssist Authenticate User.
  3. Change to the Session Values tab.
  4. Click the Plus ( ).
  5. Select emailVerified.
  6. Click OK.
  7. open the second SecurityAssist Authenticate User.
  8. Change to the Session Values tab.
  9. Click the Plus ( ).
  10. Select emailVerified.
  11. Click OK.
  12. Save the page.

arrow downCreate the restrict access rule

The next step in this magical journey of self discovery is to create an access rule for restricted pages. It will check if a user is logged in, and if they aren't, access will be restricted. If they are, it then checks if their account has been verified.

  1. In the menu bar, click WebAssist > SecurityAssist > Manage Site Access > Access Rules Manager.
  2. Click Plus ( ).
  3. Set the name to VerifiedUser.
  4. Click Plus ( ).
  5. Select the Restrict radio button.
  6. For the value field, click the lightning bolt.
  7. Expand the Session list.
  8. Select the SecurityAssist_UserID.
  9. Click OK.
  10. Click Plus ( ).
  11. For the value field, click the lightning bolt.
  12. Expand the Session list.
  13. Select emailVerified.
  14. Click OK.
  15. Set the Compare to value for the Allow condition to 1.
  16. Click OK.

arrow downAdd URL resend function

If a user has registered and their verification link has disappeared, or they have changed their emails and need to reverify, there needs to be a way for them to request a new verification URL easily. This step covers adding such functionality.

  1. Open the userupdate.php page.
  2. Add the following text to the top of the page:
    Your email hasn't been verified. Please click here and we will email you a new link.

  3. Select the text you just added.
  4. In the Server Behaviors panel, click Plus ( ).
  5. Select WebAssist > SecurityAssist > Show Region.
  6. Set the Rule to Not VerifiedUser.
  7. Click OK.
  8. Select the text "click here" from the text that was added a few steps back.
  9. In the properties inspector, set the link to the highlighted text to be:
    userupdate.php?send=true

  10. In the Bindings panel, click Plus ( ).
  11. Select URL Variable.
  12. Set the Name to send.
  13. Click OK.
  14. In the menu bar, click WebAssist > Create Email Message.
  15. For the Trigger field, click the lightning bolt.
  16. Expand the URL list.
  17. Select send.
  18. Click OK.
  19. In the From field, enter the email you wish your verification email to come from.
  20. For the To field, click the lightning bolt.
  21. Expand the Recordset (SecurityAssistuser) list.
  22. Select UserEmail.
  23. Click OK.
  24. For the Subject, enter "Verify your email".
  25. Click Finish.
  26. Open the old registration email that was edited earlier to include the verification link.
  27. Select the link that has the verification URL.
  28. Return to the new email that was created for resending the link.
  29. Edit the email how you wish.
  30. Paste the Verification email in the email body.
  31. View the page in Code View.
  32. In the URL, select the following text:
    <?php echo((isset($_POST["Registration_group_Email"]))?$_POST["Registration_group_Email"]:"") ?>

  33. And replace it with the following code:
    <?php echo $row_SecurityAssistusers['UserEmail']; ?>

  34. Scroll to the top of the page.
  35. Add the following line after the very first <?php tag:
  36. global $row_SecurityAssistusers;

  37. Save your page.
  38. Open the user update.php page again.
  39. In the Server Behaviors panel, open the Update Record (users) Server Behavior.
  40. Click the Bindings tab.
  41. Select emailVerified from the Column column.
  42. Set the Value to the following code:
    <?php echo(($row_SecurityAssistusers['UserEmail'] != $_POST["User_Update_group_Email"])? '0': $row_SecurityAssistusers['emailVerified']); ?>

  43. Click the Bindings tab.
  44. Click OK.
  45. In the Server Behaviors panel, click Plus ( ).
  46. Select WebAssist > Cookies > Set Session Value.
  47. For the Trigger field, click the lightning bolt.
  48. Expand the URL list.
  49. Select send.
  50. Click OK.
  51. Set the Name to rpw.
  52. For the Value field, click the lightning bolt.
  53. Expand the SecurityAssist list.
  54. Select Random Password.
  55. Click OK.
  56. Click OK once again.
  57. Click OK for the third and final time, thank goodness.
  58. In the Server Behaviors panel, click Plus ( ).
  59. Select WebAssist > DataAssist > Update > Update Single Record.
  60. For the Trigger field, click the lightning bolt.
  61. Expand the URL list.
  62. Select send.
  63. Click OK.
  64. Make sure the Connection is set to the correct connection.
  65. Make sure the users table is set as the Table.
  66. for the Value field, click the lightning bolt.
  67. Expand the Recordset (SecurityAssistusers) list.
  68. Select UserID.
  69. Click OK.
  70. Give someone a big, friendly hug.
  71. Click the Bindings tab.
  72. Select randomString from the Column column.
  73. For the Value field, click the lightning bolt.
  74. Expand the Session list.
  75. Select rpw.
  76. Click OK.
  77. And one more OK.
  78. Save the page.


Congratulations are in order! When a logged in, and unverified user clicks the link, they will have a fresh, new link sent to them.

arrow downLock your site down

And here we are... the end of the road. The very last step you want to perform, is locking your site down to keep unverified users, and users who are not logged in, from accessing pages that they shouldn't, and giving access to logged in and verified users.

You going to do the following steps for each page you want secured.

  1. In the menu bar, Click WebAssist > SecurityAssist > Manage Site Access > Access Pages Manager.
  2. Select the page you want to lock down from the File Name column.
  3. For the Grant access if field, select VerifiedUser.
  4. For the If access denied, go to field, select userupdate.php.
  5. Once all pages are configured, click OK.
  6. Save everything. Twice.

arrow downWhat to do next...

You did it! This was a fairly advanced tutorial, and you aced it, champ! You've now created a very professional double opt in registration system, and you're ready to create them for all of your and your client's sites.

arrow downReviews and comments

Comments will be sent to the author of this tutorial and may not be answered immediately. For general help from WebAssist, please visit technical support.

Sign in to add comments
rating
rating

sysop349733: 10 Years, 8 Months, 2 Weeks, 4 Days, 22 Hours, 4 Minutes ago

Excellent! Not only is the process described with precision, but in following these instructions, I learned a little about how to better utilize Webassist server behaviors and bindings.

Thank you.

Massimo: 10 Years, 2 Months, 1 Week, 1 Day, 11 Hours, 58 Minutes ago

Excellent tutorial as all made from web assist!
I have a question: How I can add a "just confirmed link message"?
I think: or add a new db field will be updated to 1 or use a show if $_SESSION["UserEmailVerified"]==1 (but in this case I have two message).
There is a better way?

Team WebAssist: 10 Years, 2 Months, 1 Week, 9 Hours, 35 Minutes ago

Massimo, Click on help in the main menu and our technical support team can assist you.

Jonas: 5 Years, 8 Months, 2 Weeks, 6 Days, 10 Hours, 7 Minutes ago

I really like your tutorials, and also this one. But unfortunately it is not up to date. With DataBridge V2 and Mysqli, much has changed. Unfortunately, I cannot follow this.

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.