Solved

Dreamweaver setup session variable

Posted on 2011-03-22
14
384 Views
Last Modified: 2012-05-11
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
Comment
Question by:axessJosh
  • 7
  • 7
14 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35192982
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
 
LVL 2

Author Comment

by:axessJosh
ID: 35193011
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
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 35193098
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:axessJosh
ID: 35193107
ok, that is what I am trying to figure out.  Can you provide an example of what that recordset would look like?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35193131
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
 
LVL 2

Author Comment

by:axessJosh
ID: 35193146
yea, i see that, but how does the userID become my new Session Variable?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35193269
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
 
LVL 2

Author Comment

by:axessJosh
ID: 35202700
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
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35202782
A bit, but at this point you need to show the PHP code for troubleshooting.
0
 
LVL 2

Author Comment

by:axessJosh
ID: 35202797
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
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35202814
I need to see the entire PHP block to make sure things are set properly.
0
 
LVL 2

Author Comment

by:axessJosh
ID: 35206939
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
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35209307
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
 
LVL 2

Author Comment

by:axessJosh
ID: 35209447
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how can i gnupg encrypt a PDF document? 12 61
Creating Functions in phpMyAdmin 8 26
JQuery Search Filter 2 28
Add Logo to Bookmark and Tab Headings in Browser 3 12
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question