Tutorials
Add extra session variables to a login
Using the standard Login User Server Behaviour in Dreamweaver MX sometimes leaves you wanting more. If you find that you need to add more session variables to that login script, here's how you do it.
Please be aware that altering the login code might mean that you can no longer edit the Login User Server Behaviour on this page from the Server Behaviours Panel.
First, you need to find the following line of code in the standard login code.
MM_rsUser.Source = "SELECT Username, Password"
Now you need to add the required columns to that SQL SELECT statement. Lets go for the UserID in this example.
MM_rsUser.Source = "SELECT UserID, Username, Password"
Now we need to create a session variable to carry this UserID value.
I have noticed some strange behaviour when doing this previously so I now follow a strict policy of assigning the session variable values in the order in which they are selected in the SQL. In this case, I want to assign the UserID before the Username.
Find the following line in the code:
Session("MM_Username") = MM_valUsername
This is where we can add our own session variables.
Bearing in mind the ordering trouble I pointed out a moment ago - add the following code above the Username line of code. Your final two lines of code will look like this - in this example!
Session("svUID") = MM_rsUser.Fields.Item("UserID").Value
Session("MM_Username") = MM_valUsername
You can add as many as you feel you need here but you should be aware that session variables are not necessarily the best way to carry data from page to page so go easy on them!
Notes
- The session variable I created is called svUID.
- It gets it's value by pulling the value out of the MM_rsUser recordset that the Login User server behaviour creates - we added the column we wanted into that recordset (UserID) and then used that value by referencing that recordset column: MM_rsUser.Fields.Item("UserID").Value.
That's it!
© Copyright 2009 - robgt.com

