Solved

Dreamweaver setup session variable

Posted on 2011-03-22
14
381 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now