- ASP - Read/Write
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·What's New?
Mail List


Write and Read A Cookie
Cookies enable you to write text directly to a users computer*. This can be used to easily recognize if a user has been to your site before or used to prevent multiple entries in to forms. The example below will take any input you type in and write it to a cookie. A hyperlink to the same page is created to demonstrate on subsequent visits (within 3 days) the user will see their input rather then the text input box. To see the cookie on your PC locate your cookie directory (typically located in C:\WINDOWS\Cookies) and find the one named www.codeave.txt. *The ability to write cookies to the PC can be restricted by the user by changing security options.
View the Output
Text View
Print View
Mail this Link
Download the Code

<% response.buffer=true
' response.buffer=true is used to because there is a mix
' of html output and response.cookies when the cookie is written

<title> Read & Write)</title>
<body bgcolor="#FFFFFF">
u_input=request.cookies ("testcookie")("u_input")
'checks for the variable u_input from a cookie named testcookie on
' the local pc.

' If the cookie does not exist or have a value for the variable
' then check to see if the user is inputting one 
if trim(u_input) = "" then 

' If the user hase enetered a value to put to the cookie write it out
if u_input <> "" then 

' Write the user input to the cookie
response.cookies ("testcookie")("u_input") = u_input

' Write the expiration date (today + 3 days) to the cookie
response.cookies ("testcookie").expires = DATE + 3 

' Read the cookie and write the value of u_input to the browser
response.write (request.cookies ("testcookie")("u_input")) %>

You text has been written to the cookie.<br>
Click <a href="<%= request.servervariables("script_name") %>" target="_blank">here</a> 
to open this page in a new window.
<% else
' If there was no cookie info and there was no value being inputted
' then display the textbox for user input %>

<form action="<%= request.servervariables("script_name") %>" method="post">
<input type=text name=u_input> <input type=submit value=Submit>
<% end if ' end check for user inputted value 
else ' if the cookie has a value 
' read the cookie and write the value of u_input to the browser
response.write (request.cookies ("testcookie")("u_input")) 
end if ' end check for cookie value %>





ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement is hosted by
    Donate Food Online with a Mouse Click at
    Donate Land Online with a Mouse Click at
    © 1999 - 2018
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3