Skip navigation
keydongle
Currently Being Moderated

How to use a user's loginID on subsequent pages?

Jul 23, 2009 10:28 PM

I'm using the Spry tools from DW CS4 with files written in PHP, and have successfully created a login page that validates the user's ID (which is their email address) and submitted password against a MySQL database that has a user table. The user table also contains fields such as their first/last name, phone, address, city/state/zip, so it isn't just a userID (email address) and their password.

 

So the problem is this. When the user successfully logs in, they are routed to a "member account" page where I want to display a dynamic table that shows their first/last name, email address, home address, city, state, zip, and phone number so they can view their current settings.

 

In trying to use the advanced record set tool, I can see where I would do a select on the user table for the various values, but what do I use to select the info for the user that has logged in? I've tried various forms of a session variable (I looked at the code on the login page and found $_SESSION['MM_Username'] and tried that on the member account page), and also tried $_POST['email'] while using a where clause, but it never seems to work right since I keep getting errors.

 

I decided to back off of using the table for a little bit and just try to display the name of the user that successfully logged in from the previous login page but I can't even seem to do that correctly.

 

Any ideas of how I can use the email address the user logged in with on the member account page to retrieve data correctly (or even to print Hi John Doe)?  I assume I'll also have to use a similar technique in case they click an "edit my account" link on the member account page to make changes to their current settings (assuming I can display them correctly on the member account page so they know something needs to be changed or not).

 

thanks in advance,

 

steve

 
Replies
  • Currently Being Moderated
    Jul 24, 2009 3:18 AM   in reply to keydongle

    Instructions on how to display a user's name after logging in are in the Dreamweaver FAQ.

     

    To use a session variable (or any other variable) in a SQL query in the Advanced Recordset dialog box, you need to use some placeholder text in the query, e.g., col1, col2, etc. You then define the runtime value of col1, col2, etc. in the Variables section of the dialog box by clicking the plus button and adding each variable one at a time.

     

    For example:

    Name: col1

    Type: Text

    Default value: -1

    Runtime value: $_SESSION['MM_Username']

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 24, 2009 6:02 AM   in reply to David_Powers

    Great reply David as always, and I'm having the same problem, but . .

    I've tried everything I can think of:

    When you use DW's Login In User it sets 2 session variables:

        $_SESSION['MM_Username'] = $loginUsername;
        $_SESSION['MM_UserGroup'] = $loginStrGroup;

     

    It then brings up the page that you request:

      $MM_redirectLoginSuccess = "UpdateProfile1.php";
      $MM_redirectLoginFailed = "LoginAgain.php";

     

    However, when you get to that page you don't have the password that the user keyed because they didn't save it in a session variable.

     

    Worse yet DW won't let you modify the the PHP to save the UserID (unique based on Email and Password) in a $_SESSION['MM_UserID].  It generates another "Log In User" if you modify the PHP.

     

    Bottom line is when you get to the Success or Failed page you just know the $_SESSION['MM_Username'], whether it was successful or failed and you know $_SESSION['MM_UserGroup'] (which I may never use).

     

    I even tried to capture it on the login form with:

    <td><input name="password" type="text" maxlength="25" id="trypw" onchange="setpw()"/></td>

    but can't because the Submit takes precedence over the onchange.

     

    I need to know the Password or the UserID but can't get at either.  Help please.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 25, 2009 3:55 AM   in reply to NCxplants

    On the success page, you have $_SESSION['MM_Username']. Use it to create a recordset containing all the details of the person who has just logged in. You can do this with the simple recordset dialog box exactly as explained in the FAQ item I pointed to before.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 27, 2009 8:01 AM   in reply to David_Powers

    I wrote my own but hate not to use DW's built in functions - - at my stage their's are more bulletproof.

    As I (should have) stated earlier UserName is an email address, which in my application may have several users with different passwords.

     

    I have 2 unique keys UserID (auto assigned number) and (UserName, Password)  to access the database and a lot of other profile information.

     

    When the user logs on they only pass UserName back, so if I used DW's Login I would need to make the user rekey Password on the success page to access their profile.

    That's why I wrote my own but would gladly back off if DW would set a session variable for UserID.

    Thanks again.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 27, 2009 10:29 AM   in reply to NCxplants

    NCxplants wrote:

     

    When the user logs on they only pass UserName back, so if I used DW's Login I would need to make the user rekey Password on the success page to access their profile.

    That's why I wrote my own but would gladly back off if DW would set a session variable for UserID.

    I don't know how many times I need to repeat this, but all you need to do is use $_SESSION['MM_Username'] on the success page as a filter to create a recordset containing the details of the UserID. As long as the page uses sessions (which it does if you add a Restrict Access to Page server behavior), the session variable will work. Assuming you call the recordset getDetails, all you need to do is add this line after the recordset code:

    $_SESSION['UserID'] = $row_getDetails['UserID'];
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points