Skip to main content
Known Participant
October 19, 2010
Question

Dreamweaver need to create a session variable or Cookie or something Help

  • October 19, 2010
  • 3 replies
  • 4507 views

I have been working for weeks I am very close but can't get over one last hurdle. I am trying to call a session variable much like dreamweaver calls mm_username. It is in the same user table as username - password - access level - Customer_id. I need to pull the session variable or cookie or however I can do it to access the customer id number so I can have customer specific information and pricing. There will be mulitple users for each customer so I need another variable besides mm_username. Help I use dreamweaver cs4 aspvbscript and sqlserver ...help

This topic has been closed for replies.

3 replies

Known Participant
October 21, 2010

FIrst off thanks for hanging with me guys being this has been a thorn in my side for two weeks. Here is the code I am not seeing the code that is listed above...where they create the mm_username

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
' *** Logout the current user.
MM_Logout = CStr(Request.ServerVariables("URL")) & "?MM_Logoutnow=1"
If (CStr(Request("MM_Logoutnow")) = "1") Then
  Session.Contents.Remove("MM_Username")
  Session.Contents.Remove("MM_UserAuthorization")
  MM_logoutRedirectPage = "/signout.asp"
  ' redirect with URL parameters (remove the "MM_Logoutnow" query param).
  if (MM_logoutRedirectPage = "") Then MM_logoutRedirectPage = CStr(Request.ServerVariables("URL"))
  If (InStr(1, UC_redirectPage, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
    MM_newQS = "?"
    For Each Item In Request.QueryString
      If (Item <> "MM_Logoutnow") Then
        If (Len(MM_newQS) > 1) Then MM_newQS = MM_newQS & "&"
        MM_newQS = MM_newQS & Item & "=" & Server.URLencode(Request.QueryString(Item))
      End If
    Next
    if (Len(MM_newQS) > 1) Then MM_logoutRedirectPage = MM_logoutRedirectPage & MM_newQS
  End If
  Response.Redirect(MM_logoutRedirectPage)
End If
%>
<!--#include virtual="/Connections/p21.asp" -->
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers="1,2"
MM_authFailedURL="/accessdenied.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
  If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
         (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
    MM_grantAccess = true
  End If
End If
If Not MM_grantAccess Then
  MM_qsChar = "?"
  If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
  MM_referrer = Request.ServerVariables("URL")
  if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
  MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
  Response.Redirect(MM_authFailedURL)
End If
%>
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "zzzzz"
If (Request.Form("item_id")  <> "") Then
  Recordset1__MMColParam = Request.Form("item_id")
End If
%>
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows

Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_p21_STRING
Recordset1_cmd.CommandText = "SELECT * FROM dbo.btb_get_customer_item_view WHERE item_id LIKE ?"
Recordset1_cmd.Prepared = true
Recordset1_cmd.Parameters.Append Recordset1_cmd.CreateParameter("param1", 200, 1, 40, Recordset1__MMColParam + "%") ' adVarChar

Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 10
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contract Part Number</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <input type="text" name="item_id" id="item_id" />
  <input type="submit" name="submit" id="submit" value="Submit" />
</form>
<p> </p>

<table border="1">
  <tr>
    <td>item_id</td>
    <td>customer_part_no</td>
    <td>item_desc</td>
    <td>Qty_Available</td>
    <td>contract_no</td>
    <td>customer_id</td>
  </tr>
  <% While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) %>
    <tr>
      <td><%=(Recordset1.Fields.Item("item_id").Value)%></td>
      <td><%=(Recordset1.Fields.Item("customer_part_no").Value)%></td>
      <td><%=(Recordset1.Fields.Item("item_desc").Value)%></td>
      <td><%=(Recordset1.Fields.Item("Qty_Available").Value)%></td>
      <td><%=(Recordset1.Fields.Item("contract_no").Value)%></td>
      <td><%=(Recordset1.Fields.Item("customer_id").Value)%></td>
    </tr>
    <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  Recordset1.MoveNext()
Wend
%>
</table>
<p><a href="<%= MM_Logout %>">Log out</a></p>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>

w1n78
Participating Frequently
October 21, 2010

you need to do it on the login page you made. that's where DW creates the MM_Username session - if you want to do it during the login process. but if you want to do it like bregent suggested you can query it on this page using the Session("MM_Username") as part of your WHERE clause in SQL. not sure which way you want to do it

w1n78
Participating Frequently
October 21, 2010

Ok got it ...but when I enter that line of code it gives me a server error now and when i take it out of the login page it is fine not sure what i am doing wrong

Session("MM_USERID") = MM_rsUser.Fields.Item("customer_id").value


what does the error say? and did you add customer_id to the SELECT query statement?

Known Participant
October 20, 2010

I have been building html pages for a while and have full understanding on that. Databases and Asp I am just getting into as our company has just began to utilitze them so I am a begginer at this. The books I have show how to make a session variable in php using dreamweaver but I cant find out how to do it in asp. This might not even be the best way to do it ...not sure. I just need to pull the customer id from the login table to help pull certain information from the database. This variable would be pulled on login and I would like to use it much like dreamweaver uses mm_username. Thanks for hanging with me and I hope you can help me out.

w1n78
Participating Frequently
October 20, 2010

in the login script that dreamweaver creates, look for the sql query. it usually only selects the username (sometimes the access type depending on how you set up the page protection). you need to add the user id column so that it becomes part of the result set. a few lines below that you will see that dreamweaver creates a session called MM_Username. you can create a session the same way it does username but this time use a different session name and use the user id column. the code should look like...

Session("MM_Username") = rsLogin.something.value("username")      ' dreamweaver code

Session("MM_UserID") = rsLogin.something.value("user_id")               ' user_id is the column name from the database

sorry i'm doing this off the top of my head. i haven't coded in asp in a long time. the rsLogin is the recordset that dreamweaver creates it might be different in your script. i tried to get as close as to what it could be. but that's how you create a session in asp

Participating Frequently
October 20, 2010

>sorry i'm doing this off the top of my head.

Looks correct to me.

Participating Frequently
October 19, 2010

Do you have a specific question? Exactly what part is not working for you? If you examine the code that DW creates to retrieve the username and store in a session variable, you'll see how to do it for any column you retrieve.

Known Participant
October 19, 2010

i have everything working except being able to pull this session variable to use it as a parameter to help sort customer specific information by there customer id which would be the session variable I am trying to pull from the login table i have built

Participating Frequently
October 19, 2010

Right. You say it's not working. What's happening? Are you getting an error?

What do you mean by 'pull the session variable'. Have you created the variable? Are you just not able to retrieve it? Or pass it to the query?  Please provide more info. Realize that we do not know your skill level and what you have already tried. It's really hard to guess.