Solved

Creating a cookie in ASP

Posted on 2001-07-20
4
230 Views
Last Modified: 2006-11-17
Hi Experts!
Im new to ASP, but not other web formats. I need a script that will ask a new user to my site his/her name and email address via a form and then store that information in a cookie. Once the user returns to my site, his/her name will be neatly displayed and the user wont have to reenter his/her information.

Thanks and good luck!
0
Comment
Question by:jacozekk
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
mattyk earned 100 total points
ID: 6304120
This should do the trick.  Let me know if you ahve any questions.

-matty

sample.asp
---------
<%
OPTION EXPLICIT
dim strFirstName,strLastName,strEmail
strFirstName = request.cookies("FirstName")
strLastName = request.cookies("LastName")
strEmail = request.cookies("Email")


'This will check for the presence of your cookies
if ( strFirstName<>"" and strLastName<>"" and strEmail<>"") then
     Response.write("Welcome back " & strFirstName & " " & strLastName)
     response.end
end if

strFirstName=request.querystring("FirstName")
strLastName = request.querystring("LastName")
strEmail = request.querystring("Email")

'this will process your form and place the info into cookies
if ( strFirstName<>"" and strLastName<>"" and strEmail<>"") then
      response.cookies("FirstName") = strFirstName
      response.cookies("FirstName").expires = Now + 7
      response.cookies("LastName") = strLastName
      response.cookies("LastName").expires = Now + 7
      response.cookies("Email") = strEmail
      response.cookies("Email").expires = Now + 7
      response.write("Welcome " & strFirstName & " " & strLastName)
      response.end
end if

%>

<form action="sample.asp">
     First Name <input type=text name=FirstName><br>
     Last Name<input type=text name=LastName><br>
     Email<input type=text name=Email><br>
     <input type=submit>
</form>
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6304892
This is the form page for user to enter

<%@Language=VBScript%>
<%
Option Explicit
Response.Buffer=True
%>

<html>

<head>
</head>

<body>

<form action="set_cookie.asp" method="post">
Name: <input type="text" name="txtName" value='<%=Request.Cookies("Name")%>'>
<br>
Email: <input type="text" name="txtEmail" value='<%=Request.Cookies("Email")%>'>
<br>
<input type="submit">
</form>

</body>

</html>



This is the set_cookie.asp page

<%@Language=VBScript%>
<%
Option Explicit
Response.Buffer=True
%>

<%
Response.Cookies("Name") = Request.Form("txtName")
Response.Cookies("Email") = Request.Form("txtEmail")
Response.Cookies("Name").Expires = Now() + 365
Response.Cookies("Email").Expires = Now() + 365

Response.Redirect("set_confirmation.asp")
%>




This is set_confirmation.asp

<html>

<head>
</head>

<body>

Cookies set and will only expire 365 days later.

</body>

</html>



hongjun
0
 
LVL 1

Author Comment

by:jacozekk
ID: 6305987
Thanks a lot for the quick answer! Sorry for the bit of a delay though! Check out my page! www.3dgamegear.com/index.asp
0
 
LVL 5

Expert Comment

by:mattyk
ID: 6306040
looks great!
-matty
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question