web 2.0

ASP & Cookies Object

ASP Response.Cookies() - Response Object Cookie is an object is used to save or vairable of data into client and executes on server and client browser.

ShotDev Focus:
- Create Cookies
- Read Cookies
- Delete Cookies

Example

asp_response_cookies1.asp


<% Option Explicit %>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<%
'*** Cookies None Key ***'
Response.Cookies("SiteName").Expires = Now + 7
Response.Cookies("Creator").Expires = Now + 7
Response.Cookies("SiteName") = "www.ShotDev.Com"
Response.Cookies("Creator") = "Mr.Weerachai Nukitram"

'*** Cookies Have Key ***'
Response.Cookies("User")("Username") = "Weerachai"
Response.Cookies("User")("Password") = "MyWin"
Response.Cookies("User")("Level") = "Admin"
Response.Cookies("User")("Status") = "Active"
Response.Cookies("User").Expires = Now + 7
Response.write("Cookies Created<br><br>")
Response.write("<a href=asp_response_cookies2.asp>Check  Cookies</a>")
%>
</body>
</html>

asp_response_cookies2.asp


<% Option Explicit %>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<%
'*** Cookies None Key ***'
Response.write "SiteName = "& Request.Cookies("SiteName")  & "<br>"
Response.write "Creator = "& Request.Cookies("Creator")  & "<br>"

Response.write("<hr>")

'*** Cookies Have Key ***'
Response.Cookies("User").Expires = Now + 7
Response.Cookies("User")("Username") = "Weerachai"
Response.Cookies("User")("Password") = "MyWin"
Response.Cookies("User")("Level") = "Admin"
Response.Cookies("User")("Status") = "Active"

Response.write "Username = "&  Request.Cookies("User")("Username") & "<br>"
Response.write "Password = "&  Request.Cookies("User")("Password") & "<br>"
Response.write "Level = "& Request.Cookies("User")("Level")  & "<br>"
Response.write "Status = "& Request.Cookies("User")("Status")  & "<br>"
Response.write("<hr>")

Dim List
IF Request.Cookies("User").HasKeys Then
For Each List In Request.Cookies("User")
Response.write List &" = " &  Request.Cookies("User")(List) & "<br>"
Next
End IF

Response.write("<br><br><a  href=asp_response_cookies3.asp>Delete Cookies</a>")
%>
</body>
</html>

asp_response_cookies3.asp


<% Option Explicit %>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<%
'*** Cookies None Key ***'
Response.Cookies("SiteName").Expires = Now
Response.Cookies("Creator").Expires = Now

'*** Cookies Have Key ***'
Response.Cookies("User").Expires = Now

Response.write("Cookies Deleted<br><br>")
Response.write("<a href=asp_response_cookies2.asp>Check  Cookies</a><br>")
Response.write("<a href=asp_response_cookies1.asp>Create  Cookies</a><br>")
%>
</body>
</html>

Create a asp file and save to path root-path/myasp/

Run
http://localhost/myasp/asp_response_cookies1.asp

Screenshot

ASP & Response.Cookies()

ASP & Response.Cookies()

ASP & Response.Cookies()

.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.