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
Solved

Creating a cookie in ASP

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to hide hide popup page refresh second time? 10 143
Select distinct 25 116
Passing Parameter to Stored Procedure 4 27
Button function on table is in trouble 3 22
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…
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…

828 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