• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Lesson 14. Restricting Access > Enabling Users to Log Out

Enabling Users to Log Out

The safest way to log out of a site is to close the browser. However, many users like to have a log-out link right in the site, and with Dreamweaver MX it's very easy to add one.

Open welcome.cfm.

The last link on this page (not yet made) will enable users to log out. What this server behavior does behind the scenes in the code is to set the session variable, which stores the username (that is, email address) and which is verified on every page, to an empty string, effectively removing the username from the session variable.

With the session variable set to an empty string, if someone attempts to visit a restricted page, the Restrict Access To Page server behavior will see the empty session variable and reject the user, sending her or him to notloggedin.cfm. Unfortunately, the use of the browser's Back button often lets users revisit restricted pages that they have recently viewed. That is why I encourage you to include a note to your user to close the browser after logging out for additional security.

In Design View, drag to select the two words, Log out.

This is how you would create a normal hyperlink, although in this situation, you will create a special hyperlink: Rather than merely containing a URL, this hyperlink calls a log-out function that redirects the user to loggedout.cfm and clears the session variable from memory.

In the Server Behaviors panel, click the + button, and choose User Authentication > Log Out User.

You should be getting very comfortable with adding server behaviors at this point.

Leave the Log Out When setting at its default, Link Clicked. In the When Done, Go To field, type or browse to loggedout.cfm. Click OK.

Dreamweaver adds the ColdFusion code needed to create the log-out behavior. It also automatically adds a hyperlink to the selection.

From a functional standpoint, you have built the complete user authentication framework of the elearning application.

Click anywhere else onscreen, and then click the newly made hyperlink. Select the <a> tag in the tag selector. In the CSS panel, select the bodytextlink style.

You need to apply the bodytextlink style to make the newly created hyperlink red, like all of the other hyperlinks in the site.

Save this file and put it on the remote server. Select index.cfm in the Site panel, and press F12 to test the site.

When testing, try everything. Try not filling out the registration form correctly. Try logging in with bogus credentials. Try to access a restricted page without logging in. Hopefully, the whole environment will work as you would expect. (The one caveat is that the Restrict Access to Page behavior is sometimes finicky, especially if you have been doing a lot of testing—that's in part because session variables sometimes take a while to expire.)



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint