Solved

Creating a cookie in ASP

Posted on 2001-07-20
4
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 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