ຄູ່ມື ASP Cookies
ຄູ່ມື Cookies ມີການຕັ້ງຂໍ້ມູນຫຼື ດຶງດູດຂໍ້ມູນຂອງ cookie. ຖ້າ cookie ບໍ່ມີ, ຈະສ້າງມັນຂຶ້ນແລະຕັ້ງຂໍ້ມູນຕາມຄວາມສັ່ງ.
ຄວາມເຫັນ:ການສັ່ງ Response.Cookies ຕ້ອງຢູ່ກ່ອນ <html> ການສັ່ງ.
ວິທີການ:
Response.Cookies(name)[(key)|.attribute]=value variablename=Request.Cookies(name)[(key)|.attribute]
ປະເພດ | ການອະທິບາຍ |
---|---|
name | ຄວາມຄິດສົມທຽບ. ປະຫວັດມະນາງຂອງ cookie. |
value | ຄວາມຄິດສົມທຽບ. ຄວາມມູນຂອງ cookie (ສະເພາະສຳລັບ Response.Cookies). |
attribute | ຄວາມຄິດສົມທຽບ. ກໍານົດຂໍ້ມູນຂອງ cookie. ສາມາດເປັນປະເພດຕ່າງໆທີ່ລົງມາລົງນັ້ນ.
|
key | ຄວາມຄິດສົມທຽບ. ກໍານົດບ່ອນທີ່ຈະຕັ້ງຂໍ້ມູນບ່ອນຫວັງ. |
ຕົວຢ່າງ
"Response.Cookies" ການສັ່ງຂອງ cookie ຫຼື ຕັ້ງຂໍ້ມູນວ່າ cookie:
<% Response.Cookies("firstname")="Alex" %>
ໃນລະຫັດການທີ່ມີຢູ່ບໍລິໂພກພາຍໃນຄຳສັ່ງ "firstname" ພວກເຮົາຈະຕັ້ງຂໍ້ມູນວ່າ alex .
ກໍ່ສາມາດຕັ້ງປະສົງຂອງ cookie ຕາມຄວາມຫວັງ ອອກຈາກວັນນີ້:
<% Response.Cookies("firstname")="Alex" Response.Cookies("firstname").Expires=#May 10,2002# %>
ປັດຈຸບັນ cookie ທີ່ມີຊື່ "firstname" ມີຄູ່ມີ "Alex" ແລະ ມີວັນສະຕິກັນສູນຂອງມັນໃນຄອມພິວເຕີ້ຂອງ user ໃນວັນທີ 10 ພຶດສະພາ 2002 .
"Request.Cookies" ສຽງສັ່ງສາມາດເອົາຄູ່ມີຫຼັງ .
ໃນຄັນຄືນດັ່ງລຽງນີ້ພວກເຮົາໄດ້ເອົາຄູ່ມີ "firstname" ແລະ ສະແດງມັນໃນໜ້າເວັບ :
<% fname=Request.Cookies("firstname") response.write("Firstname=" & fname) %>
ການສະແດງອາກາດ
Firstname=Alex
cookie ສາມາດມີຄູ່ມີຫຼາຍຄວາມຄືບໜຶ່ງ . ພວກເຂົາເອີ້ນວ່າ cookie ມີ key .
ໃນຄັນຄືນດັ່ງລຽງນີ້ພວກເຮົາຈະສ້າງ cookie ທີ່ມີຊື່ "user" . "user" cookie ມີ key ທີ່ບັນຈຸຂໍ້ມູນຂອງ user .
<% Response.Cookies("user")("firstname")="John" Response.Cookies("user")("lastname")="Adams" Response.Cookies("user")("country")="UK" Response.Cookies("user")("age")="25" %>
ລະບັບທີ່ຖືກຂຽນສາມາດອ່ານຄວາມຂອງ cookie ທີ່ server ໄດ້ສົ່ງໄປໃຫ້ user . ຍັງມີ HasKeys ທີ່ພິຈາລະນາວ່າ cookie ມີ key ຫຼືບໍ່ :
<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 ການຂຽນຄູ່ມີຄຳສັ່ງ x & "=" & Request.Cookies(x) & "<br />" end if response.write "</p>" next %> </body> </html> %>
ການສະແດງອາກາດ
firstname=Alex user:firstname=John user:lastname=Adams user: country=UK user: age=25