...

View Full Version : Need help with ASP and cookies



beckgin
08-19-2004, 05:24 PM
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>

miranda
08-19-2004, 05:51 PM
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.


<%
'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

beckgin
08-19-2004, 06:31 PM
Thanks for the reply. TO verify, I place this cookie code on the page that has the link to the pdf, correct?

miranda
08-19-2004, 07:03 PM
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


Response.Cookies ("name_of_cookie")("hasRegistered") = "true"


now on the page that has the link use this


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum