Solved

Creating a cookie in ASP

Posted on 2001-07-20
4
232 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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/…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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