एएसपी कुकीज़ संग्रह
❮ पूर्ण प्रतिक्रिया वस्तु संदर्भ
कुकी संग्रह का उपयोग कुकी मान सेट करने या प्राप्त करने के लिए किया जाता है। यदि कुकी मौजूद नहीं है, तो इसे बनाया जाएगा, और निर्दिष्ट मान लें।
नोट: Response.Cookies कमांड <html> टैग से पहले दिखना चाहिए।
वाक्य - विन्यास
Response.Cookies(name)[(key)|.attribute]=value
variablename=Request.Cookies(name)[(key)|.attribute]
Parameter | Description |
---|---|
name | Required. The name of the cookie |
value | Required for the Response.Cookies command. The value of the cookie |
attribute | Optional. Specifies information about the cookie. Can be one of the following parameters:
|
key | Optional. Specifies the key to where the value is assigned |
उदाहरण
कुकी बनाने या कुकी मान सेट करने के लिए "Response.Cookies" कमांड का उपयोग किया जाता है:
<%
Response.Cookies("firstname")="Alex"
%>
उपरोक्त कोड में, हमने "फर्स्टनाम" नामक एक कुकी बनाई है और इसे "एलेक्स" मान दिया है।
कुकी के लिए कुछ विशेषताओं को निर्दिष्ट करना भी संभव है, जैसे किसी कुकी के समाप्त होने की तिथि निर्धारित करना:
<%
Response.Cookies("firstname")="Alex"
Response.Cookies("firstname").Expires=#May 10,2002#
%>
अब "फर्स्टनाम" नाम की कुकी में "एलेक्स" का मान है, और यह उपयोगकर्ता के कंप्यूटर से 10 मई, 2002 को समाप्त हो जाएगा।
कुकी मान प्राप्त करने के लिए "Request.Cookies" कमांड का उपयोग किया जाता है।
नीचे दिए गए उदाहरण में, हम कुकी "फर्स्टनाम" का मान प्राप्त करते हैं और इसे एक पृष्ठ पर प्रदर्शित करते हैं:
<%
fname=Request.Cookies("firstname")
response.write("Firstname=" & fname)
%>
आउटपुट:
Firstname=Alex
एक कुकी में कई मानों का संग्रह भी हो सकता है। हम कहते हैं कि कुकी में चाबियां होती हैं।
नीचे दिए गए उदाहरण में, हम "उपयोगकर्ता" नामक एक कुकी-संग्रह बनाएंगे। "उपयोगकर्ता" कुकी में कुंजियाँ होती हैं जिनमें उपयोगकर्ता के बारे में जानकारी होती है:
<%
Response.Cookies("user")("firstname")="John"
Response.Cookies("user")("lastname")="Smith"
Response.Cookies("user")("country")="Norway"
Response.Cookies("user")("age")="25"
%>
नीचे दिया गया कोड उन सभी कुकीज़ को पढ़ता है जिन्हें आपके सर्वर ने किसी उपयोगकर्ता को भेजा है। ध्यान दें कि कोड जांचता है कि कुकी में HasKeys संपत्ति के साथ कुंजी है या नहीं:
<html>
<body>
<%
dim x,y
for each x in Request.Cookies
response.write("<p>")
if Request.Cookies(x).HasKeys then
for each y in Request.Cookies(x)
response.write(x & ":" & y & "=" & Request.Cookies(x)(y))
response.write("<br>")
next
else
Response.Write(x & "=" & Request.Cookies(x) & "<br>")
end if
response.write "</p>"
next
%>
</body>
</html>
%>
आउटपुट:
firstname=Alex
user:firstname=John
user:lastname=Smith
user:
country=Norway
user:
age=25
❮ पूर्ण प्रतिक्रिया वस्तु संदर्भ