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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with ASP and cookies

    I have a link on a web site that requires this: at first visit, click on the link and go to a register page, fill in the 3 required fields and be redirected to a pdf. I know how to do that. The part I am stuck on is this...at the second visit, visitor clicks on link and goes directly to pdf. I figured there will be two pages, one to detect a cookie and if it is true, redirect to pdf. If it is false, then go to register.asp. The page that has the link to the pdf will have something like the code below. The pdf.asp page will determine if the visitor has been here before. I don't know how to create this page. I would assume that it will look for a cookie with the pdf, dir, name and type. I've been searching for any tutorials or direction. Any help would be appreciated.
    <script language="JavaScript">
    <!--
    function popLogin(pdf,dir,name,type) {
    pdf = escape(pdf);
    dir = escape(dir);
    name = escape(name);
    type = escape(type);

    theURL = "/pdf.asp?pdf=" + pdf + "&dir=" + dir + "&name=" + name + "&type=" + type;
    window.open(theURL ,"","scrollbars=1,resizable=1,height=550,width=600,left =200,top=200");
    }
    // -->
    </script>
    </head>
    <body><a href="javascrip:Login('whitepaper','docs','Product
    Highlight Re-ratio & Ratio Splitter Tools : Whitepaper')" style="text-decoration:underline";>Product
    Highlight Re-ratio & Ratio Splitter Tools - Gain added flexibility and economy form your two color microarray experiments</a>

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Is this an intranet or internet application? If internet then what about a user who would use multiple computers? Like one at home, one at the office, and a laptop? they would be required to register all 3 times in this instance because the cookie resides on the computer.

    That said cookies and asp are easy.
    Code:
    <% 
    'Write the cookie   
    Response.Cookies ("hasRegistered")
    'you can also name the cookie
    Response.Cookies ("name_of_cookie")("hasRegistered")
    'you can also assign a value to either of these
    Response.Cookies ("hasRegistered") = "true"
    Response.Cookies ("name_of_cookie")("hasRegistered") = "true"
    
    
    'Read the cookie
    Request.Cookies ("hasRegistered")
    Request.Cookies("name_of_cookie")("hasRegistered")
    
    'to test if this cookie exists just use it in an If/Then statement
    If Request.Cookies ("name_of_cookie")("hasRegistered") Then
         Response.Redirect "your_pdf_page"
    Else
         Response.Redirect "your_registration_page"
    End If
    
    'if you have assigned a value just test for that value
    If Request.Cookies ("name_of_cookie")("hasRegistered") = "true" Then
         Response.Redirect "your_pdf_page"
    Else
         Response.Redirect "your_registration_page"
    End If
    
    
    'to expire a cookie use 
    Response.Cookies("name_of_cookie").Expires = 12/31/2004

  • #3
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply. TO verify, I place this cookie code on the page that has the link to the pdf, correct?

  • #4
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    in the previous example you would place the if/then statement on an intermediary page to check for the cookie.

    To simplify it even more, place this on your page that handles the registration after the user has registered. place the cookie at the end of the coding
    Code:
    Response.Cookies ("name_of_cookie")("hasRegistered") = "true"
    now on the page that has the link use this
    Code:
    If Request.Cookies ("name_of_cookie")("hasRegistered") = "true" Then
            Response.Write "<a href=""Link_to_your_pdf_page"">pdf page</a>"
    Else
            Response.Write "<a href=""Link_to_your_registration_page"">Register</a>"
    End If
    Last edited by miranda; 08-19-2004 at 08:07 PM.


  •  

    Posting Permissions

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