Convert Session Variables over to Cookies

Results 1 to 3 of 3

Thread: Convert Session Variables over to Cookies

  1. #1
    Chad Franklin Guest

    Default Convert Session Variables over to Cookies

    I&#039m using session variables in my Global.asa file. Is it relatively easy to convert session variable to cookies. I don&#039t have a lot of experience with cookies. This is my code in my global.asa file.<BR>&#060;script language="vbscript" runat=server><BR>Sub Application_OnStart<BR>&#039Tax percentage to add to order total<BR>Dim stax<BR>stax = 0.21<BR>Application("taxP") = stax<BR>End Sub<BR><BR>Sub Application_OnEnd<BR><BR>End Sub<BR><BR>Sub Session_OnStart<BR>&#039Shopping cart array<BR>Const cartAttributes = 5<BR>Const maxCartItems = 10<BR>ReDim arrcart(cartAttributes,maxCartItems)<BR><BR>Sessio n("MyCart") = arrcart<BR>Session("cartItem") = 0<BR><BR>End Sub<BR><BR>Sub Session_OnEnd<BR><BR>End Sub<BR><BR>&#060;/script> <BR>

  2. #2
    e Guest

    Default RE: Convert Session Variables over to Cookies

    There is a article on this<BR>that might help:<BR><BR>http://www.4guysfromrolla.com/webtech/051099-1.shtml<BR><BR>the guy that wrote it is very smart :)<BR>heh.<BR><BR>hope this helps

  3. #3
    Chad Franklin Guest

    Default Need more help!!

    I tried converting my session variables to cookies and I just get one error after the other. Just when I think I fixed something it find an error further down the page. I could really use your help. This is my page that is giving me problems. I&#039m going to give the orginal page that works with session variable, because I probable mucked things up a bit.<BR><BR>&#060;%@ Language=VBScript &#037;&#062;<BR>&#060;% Option Explicit &#037;&#062;<BR>&#060;!-- #include file="db.inc" --><BR>&#060;%<BR>Dim prodid<BR>Dim quantity<BR>Dim arrCart<BR>Dim scartItem<BR>prodid = Request.Form("fproductid")<BR>quantity = Request.Form("fquantity")<BR>arrCart = Session("MyCart")<BR>scartItem = Session("cartItem")<BR><BR>If scartItem = "" Then<BR> Response.Redirect "error.asp?msg=" & Server.URLEncode ("We noticed you do not accept cookies. Please enable cookies to shop.")<BR>End If<BR><BR>If prodid &#060;> "" Then<BR> If scartItem &#060; maxCartItems Then<BR> scartItem = scartItem + 1<BR> End If<BR> Session("cartItem") = scartItem<BR> Dim rsItem<BR> Set rsItem = Server.CreateObject("ADODB.Recordset")<BR> rsItem.Open "products", dbc, adOpenForwardOnly,adLockReadOnly,adCmdTable<BR> rsItem.Filter = "catalogID = " & prodid<BR> If Not rsItem.EOF Then<BR> arrCart(cProductid,scartItem) = rsItem("catalogID")<BR> arrCart(cProductCode,scartItem) = rsItem("ccode")<BR> arrCart(cProductname,scartItem) = rsItem("cname")<BR> arrCart(cQuantity,scartItem) = CInt(quantity)<BR> arrCart(cUnitPrice,scartItem) = rsItem("cprice")<BR> Session("MyCart") = arrCart<BR> rsItem.Close<BR> dbc.Close<BR> End If<BR>Else<BR><BR>Dim strAction<BR>strAction = UCase(Left(Request.Form("action"),5))<BR><BR>Selec t Case strAction<BR><BR>Case "CONTI"<BR> Response.Redirect "Default.asp"<BR> <BR>Case "RECAL"<BR><BR> For i = 1 To scartItem<BR> Dim tquantity<BR> tquantity = Request.Form("Quantity" & Cstr(i))<BR> arrCart(cQuantity,i) = CInt(tquantity)<BR> Next<BR> <BR> For i = 1 to scartItem<BR> Dim confirm<BR> confirm = Request.Form("selected" & CStr(i))<BR> If confirm &#060;> "yes" Then<BR> scartItem = scartItem - 1<BR> Dim x<BR> For x = 1 to UBound(arrCart,1)<BR> arrCart(x,i) = ""<BR> Next<BR> Dim n<BR> n = i<BR> while n &#060; UBound(arrCart,2)<BR> For x = 1 to UBound(arrCart,1)<BR> arrCart(x,n) = arrCart(x,n + 1)<BR> arrCart(x,n + 1) = ""<BR> Next<BR> n = n + 1<BR> wend <BR> end If<BR> Next<BR> Session("cartItem") = scartItem<BR> Session("MyCart") = arrCart<BR><BR><BR>Case "PROCE"<BR> Response.Redirect "customer.asp"<BR><BR>End Select<BR>End If<BR><BR><BR>&#037;&#062;<BR><BR>&#060;html><BR>& #060;head><BR>&#060;title>Shopping cart items&#060;/title><BR><BR>&#060;/head><BR>&#060;body><BR>&#060;h3>&#060;font face="Arial">Shopping Cart Items:&#060;/font>&#060;/h3><BR>&#060;form action="addprod.asp" method="POST"><BR>&#060;table border="0" cellPadding="3" cellSpacing="2" width="100%"><BR> &#060;tr bgColor="darkblue"><BR> &#060;td>&#060;font color="white" face style="BACKGROUND-COLOR: #00008b">Product <BR> code&#060;/font>&#060;/td><BR> &#060;td>&#060;font color="white" face style="BACKGROUND-COLOR: #00008b">Product name&#060;/font>&#060;/td><BR> &#060;td>&#060;font color="white" face style="BACKGROUND-COLOR: #00008b">Quantity&#060;/font>&#060;/td><BR> &#060;td>&#060;font color="white" face style="BACKGROUND-COLOR: #00008b">Unit <BR> Price&#060;/font>&#060;/td><BR> &#060;td>&#060;font color="white" face style="BACKGROUND-COLOR: #00008b">Total&#060;/font>&#060;/td>&#060;/tr><BR>&#060;%<BR>Dim isubtotal, i<BR>isubtotal = 0<BR>For i = 1 to scartItem<BR>&#037;&#062;<BR> &#060;tr bgColor="navajowhite"><BR> &#060;td>&#060;input name="selected&#060;%= Cstr(i)&#037;&#062;" type="checkbox" value="yes" checked>&#060;%= arrCart(cProductCode,i) &#037;&#062;&#060;/td><BR> &#060;td>&#060;%= arrCart(cProductname,i) &#037;&#062;&#060;/td><BR> &#060;td>&#060;input type="text" name="quantity&#060;%= CStr(i) &#037;&#062;" value="&#060;%= arrCart(cQuantity,i) &#037;&#062;">&#060;/td><BR> &#060;td>&#060;%= FormatCurrency(arrCart(cUnitPrice,i),2) &#037;&#062;&#060;/td><BR> &#060;td>&#060;%= FormatCurrency(arrCart(cUnitPrice,i) * arrCart(cQuantity,i),2) &#037;&#062;&#060;/td>&#060;/tr><BR>&#060;%<BR> isubtotal = isubtotal + (arrCart(cUnitPrice,i) * arrCart(cQuantity,i))<BR> Next<BR>&#037;&#062; <BR> &#060;tr><BR> &#060;td>&#060;/td><BR> &#060;td>&#060;/td><BR> &#060;td>&#060;/td><BR> &#060;td bgColor="darkblue">&#060;font color="white" face style="BACKGROUND-COLOR: #00008b">Total&#060;/font>&#060;/td><BR> &#060;td bgColor="lightgoldenrodyellow">&#060;%= FormatCurrency(isubtotal,2) &#037;&#062;&#060;/td>&#060;/tr>&#060;/table>&#060;/p><BR>&#060;p>&#060;input name="action" type="submit" value="Continue shopping"> <BR>&#060;input name="action" type="submit" value="Recalculate"> <BR><BR>&#060;input name="action" type="submit" value="Proceed to check out"><BR><BR><BR>&#060;/p>&#060;/form><BR><BR><BR>&#060;/body><BR>&#060;/html>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •