Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cookies Question from a newbie

    Hi Guys:

    Listen, I have a form that is created with normal text inputs, radio buttons and drop down menus. This page is a HTML page. Than on submit goes to the process ASP page. Now to create and check if there are any cookies already where does the code go. I've been to several pages and understand the codes I just don't know if they go in the HTML page or the ASP page. The page already validates the data etc. I just need to know where I need to put the creation and checking of the cookies!

    I hope you can understand what I'm trying to do. Please help me if you can to just tell me what part goes where! Thanks in advance!

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    if you are creating the cookie in ASP then the cookie code goes in the asp part. If you are creating the cookie using client side javascript then the code goes with the html.

  • #3
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://www.w3schools.com/asp/asp_cookies.asp

    Use an If/Else statement to check if the cookie exists, if not create it.

    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <%
    If Request.QueryString("setcookie") = "set" Then
    	Response.Cookies("fname") = "Degsy"
    	Response.Redirect(Request.ServerVariables("SCRIPT_NAME"))
    Elseif Request.QueryString("setcookie") = "del" Then
    	Response.Cookies("fname").Expires=#May 10,2002#
    	Response.Redirect(Request.ServerVariables("SCRIPT_NAME"))
    End If
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <%If Request.Cookies("fname") = "" Then%>
    <a href="<%=Request.ServerVariables("SCRIPT_NAME")%>?setcookie=set">Set Cookie</a>
    <%Else%>
    Welcome 
    <%
    fname = Request.Cookies("fname")
    Response.Write fname
    %>
    <a href="<%=Request.ServerVariables("SCRIPT_NAME")%>?setcookie=del">Delete Cookie</a>
    <%End If%>
    </body>
    </html>

  • #4
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay, if you only want your ASP Process page to search for the cookies then it needs to go into the ASP portion of that page. My question is if your tracking itemS then why not use sessions first, cookies can become your worst nightmare.... second typically for everytime I have been needing to track something in a session / cookie the need has been for every page. If thats the case then it changes your situation entirely. For that case you would need to make all the pages ASP pages, and then either make the validation / cookie checker in a separate include file. Probably more confused from my answer but I just dont see the need of checking cookies if its a one time process page.

  • #5
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    ASP sessions are unwritten cookies. The problem is they use server memory. So if you have a lot of session variables you will drag your site's response time down. Sessions can be great if used properly but they can also be a nightmare.


  •  

    Posting Permissions

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