Solved

Creating a cookie in ASP

Posted on 2001-07-20
4
228 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
looks great!
-matty
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now