• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 392
  • Last Modified:

Dreamweaver setup session variable

I am using Dreamweaver to build a dyamic portal using the user login and user restriction plugins.  I know that the login sets a Session Variable of MM_Username.  I have setup my table structure where the relative key is userID.  My username field is simply the users email.  How can I either set the session variable to MM_userID at login or add it through a recordset on the first page.

I'm kinda stuck.
0
axessJosh
Asked:
axessJosh
  • 7
  • 7
1 Solution
 
Jason C. LevineNo oneCommented:
Hi axessJosh,

When the user logs in, the DW Login Behavior sets $_SESSION['MM_Username'] so it is available on any future page provided you have session_start() called in the PHP code.

I'm not sure I understand the rest of your question...are you looking to add another variable other than the email address?
0
 
axessJoshAuthor Commented:
yes, i am trying to add another variable.

As i understand it, the session variable $_SESSION['MM_Username'] is the user login credential used.  What i need is for that users 'userID' to become the session variable that is used for all the other pages in the portal as all of my database tables are linked by userID not username.
0
 
Jason C. LevineNo oneCommented:
Okay, there are two ways to do it.  You can manually add variables to the session during the login by changing the code DW generates or you can have a recordset lookup on each page using MM_Username to filter it to the matching records.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
axessJoshAuthor Commented:
ok, that is what I am trying to figure out.  Can you provide an example of what that recordset would look like?
0
 
Jason C. LevineNo oneCommented:
In DW, just add a new recordset to the page using the simple wizard and set the filter options to:

columnname
 =
Session Variable
MM_Username

Again, be sure that session_start() appears in the code of each page containing the above recordset or it won't work.
0
 
axessJoshAuthor Commented:
yea, i see that, but how does the userID become my new Session Variable?
0
 
Jason C. LevineNo oneCommented:
If you have the recordset on every page, you don't need it to be a session variable.  It's available as a recordset variable ($row_YourRecordSet['whatever']).

That's why the either/or in http:#a35193098
0
 
axessJoshAuthor Commented:
Still having trouble.

i setup the recordset to query the data by the session variable, but when i put a repeat region on the dataset, it shows all data in the database regardless of logged in user.  In my content table, i am making the relation to the users table by userID.  the SESSION variable is using the useremail address for login, but I am not able to grab the userID anywhere in the session?  

does my question make sense?
0
 
Jason C. LevineNo oneCommented:
A bit, but at this point you need to show the PHP code for troubleshooting.
0
 
axessJoshAuthor Commented:
Below is the SQL statement:

$colname_rsContent = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_rsContent = $_SESSION['MM_Username'];
}
mysql_select_db($database_con_message, $con_message);
$query_rsContent = sprintf("SELECT contTitle, contentText, contentDate, contScrRef, tblcont.userID, tblusers.userEmail, tblusers.userID FROM tblcont, tblusers WHERE tblusers.userEmail = %s AND tblcont.userID = tblusers.userID", GetSQLValueString($colname_rsContent, "int"));
$rsContent = mysql_query($query_rsContent, $con_message) or die(mysql_error());
$row_rsContent = mysql_fetch_assoc($rsContent);
$totalRows_rsContent = mysql_num_rows($rsContent);
?>

let me know if you need more.
0
 
Jason C. LevineNo oneCommented:
I need to see the entire PHP block to make sure things are set properly.
0
 
axessJoshAuthor Commented:
My code is attached.  As you'll see, the session variable is working fine, giving me the userFirstName as I want.  What is not working and I can't figure out is how to filter my content by userID which is the INT field i am using to connect the logged in user to their content.  I may be overthinking this, but for some reason its not making sense.
main.php
0
 
Jason C. LevineNo oneCommented:
Thanks.  So let me understand this a bit better:

$query_rsContent = sprintf("SELECT contTitle, contentText, contentDate, contScrRef, tblcont.userID, tblusers.userEmail, tblusers.userID FROM tblcont, tblusers WHERE tblusers.userEmail = %s AND tblcont.userID = tblusers.userID", GetSQLValueString($colname_rsContent, "int"));

$_SESSION['MM_Username'] is an email address, right?  If so, this query won't work because of this part:

GetSQLValueString($colname_rsContent, "int"));

You are telling GetSQLValueString function to validate against an integer.  It should be:

GetSQLValueString($colname_rsContent, "text"));

If that doesn't work, add the following line in the body of the page for debugging the query:

<?php echo $query_rsContent; ?>
0
 
axessJoshAuthor Commented:
Actually, your previous comment, ID: 35193098, was the solution for me.  I actually went through another book I have and found how to add my own session variable, using the code:

$_SESSION['MM_UserID'] = $row_rsUser['userID'];
?>

From that, i am now able to use that variable the way i had originally intended.  thanks for the guidance.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now