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