?
Solved

Dreamweaver setup session variable

Posted on 2011-03-22
14
Medium Priority
?
387 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

765 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