Display user details using session variables

In this tutorial topic you will build the details page. This is the page where the user will be redirected to once he/she successfully logs in onto your site (as set here). From the session variables created upon login, this page will display the private information (full name, site username, e-mail address, billing address) of the currently logged-in user. Users that have not yet logged in must be prevented from accessing this page, as it would display only empty fields (the session variables do not exist).To allow only logged-in users see the page content, apply the Restrict Access To Page server behavior.

Access the server behavior from the Application panel, Server Behaviors -> + -> MX Kollection -> User Login -> Restrict Access To Page. Configure it as shown below:

 

  1. Since we are not using access levels in this application, leave the first radio button (Username and password) checked.

  2. Click OK to close the dialog box. Access to this page will be now restricted only to the logged-in user in the current session.

 

The page design will be a simple one, but you can enrich it according to your preferences. Open the details page in Dreamweaver and make sure you are in Design view. If not, select View -> Design. In different paragraphs, type the following text parts:

Hello

Your username is:

Your e-mail address is:

Your billing address is:

 

In the Application panel on the right, click the Bindings tab and expand the Session tree menu that lists all the session variables that were added to the site. Except for the kt_login_id, drag and drop each session variable in the details page as shown in the image below (at the end of the four paragraphs you just created, press the Space key and then drop the session variables):

 

At the end of the first paragraph (after the session variable), add a comma. At the end of the next three paragraphs add a period. To better point out the private information of the user, select each of the session variables dropped in page and set them to be displayed in bold style from the Property Inspector:

 

After a user checks out his/her private information, he/she should logout from their site account. In this regard, create a new paragraph after the last one (the one with the billing address) by pressing the Enter key. Type 'Logout', select it, and then apply the Logout User server behavior from the Application panel, Server Behaviors -> + -> MX Kollection -> User Login. Configure it as shown in the following image:

 

  1. Leave the first radio button (Link clicked) checked. The 'Logout' text you just typed will become the logout link.

  2. In the After logout, go to text box enter the index page. You can use the Browse button to locate it.

  3. Click OK to apply the Logout User server behavior to your page.

 

At this point, the details page in Dreamweaver should look like this:

 

If you save it, upload it to the server and then preview it in the browser, you will be first redirected to the index page. This happens because the details page has the access to it restricted only for the logged-in user. So you will be asked to login first. You can use one of the two user accounts provided for this tutorial (username: john, password: root):

 

By pressing the Login button you will be redirected to the details page in browser, where the logged-in user can view his/her private information, displayed with the help of session variables:

 

By following this very simple tutorial, you learned how to use session variables in order to display information about the currently logged-in user.