ASP Cookie
- အရှေ့ပိုင်း စာရင်း ASP ပါဝင်သော ပန်းခြံ
- နောက်ပိုင်း စာရင်း ASP Session
cookie 常用来对用户进行识别。
实例
- Welcome cookie
- 如何创建欢迎 cookie。
什么是 Cookie?
cookie 常用来对用户进行识别。cookie 是一种服务器留在用户电脑中的小文件。每当同一台电脑通过浏览器请求页面时,这台电脑也会发送 cookie。通过 ASP,您能够创建并取回 cookie 的值。
如何创建 cookie?
"Response.Cookies" အမိန့် သည် အားကစားအမျိုးအစား ကို ဖွင့်ပေးရန် အသုံးပြုသည်。
အကြောင်းကြားငြား:Response.Cookies အမိန့် သည် <html> အချက်အလက် အောက်မှ သုံးပါလိမ့်မည်。
အောက်အရာများတွင်၊ ကျွန်ုပ်တို့သည် "firstname" အမည်ရှိ အားကစားအမျိုးစား ကို ဖွင့်ပေးလိမ့်မည် နှင့် "Alex" ကို ချိတ်ဆက်ပါလိမ့်မည်:
<% Response.Cookies("user")("firstname")="Alex" %>
အားကစားအမျိုးအစား အချက်အလက်များ ကို ချိတ်ဆက်ရန် လည်း အခွင့်ရှိပါသည်၊ ဥပမာ၊ အားကစားအမျိုးအစား အား ပျက်ကွက်ချိန် ကို အစားထိုးရန်:
<% Response.Cookies("user")("firstname")="Alex" Response.Cookies("firstname").Expires=#May 10,2020# %>
အားကစားအမျိုးအစား အား မြင်တွေ့ရန် ဘယ်လိုဖြစ်သလဲ?
"Request.Cookies" အမိန့် သည် အားကစားအမျိုးအစား အား မြင်တွေ့ရန် အသုံးပြုသည်。
အောက်အရာများတွင်၊ ကျွန်ုပ်တို့သည် "firstname" အမည်ရှိ အားကစားအမျိုးအစား ကို နှင့် အားကစားအမျိုးစား ကို ပြန်လည်ရယူပြီး စာမေးပါက ပြထားပါလိမ့်မည်:
<% fname=Request.Cookies("firstname") response.write("Firstname=" & fname) %>
输出:
Firstname=Alex
ကြိတ်သားပါဝင်သော အားကစားအမျိုးအစား
အားကစားအမျိုးအစားများ တစ်ခုခုပါး များစွာသော အရာများ ကို ပါဝင်သော အားကစားအမျိုးအစား တစ်ခု သည် ကြိတ်သား (Keys) ကို ပါဝင်သည် ဟု ပြောနိုင်ပါသည်。
အောက်အရာများတွင်၊ ကျွန်ုပ်တို့သည် "user" အမည်ရှိ အားကစားအမျိုးအစား အစိုးရွက် ကို ဖွင့်ပေးလိမ့်မည် "user" အားကစားအမျိုးအစား အစိုးရွက် သည် အသုံးစွဲသူ၏ သတင်းအချက်အလက်များ ပါဝင်သော ကြိတ်သားများ ရှိသည်:
<% Response.Cookies("user")("firstname")="John" Response.Cookies("user")("lastname")="Adams" Response.Cookies("user")("country")="UK" Response.Cookies("user")("age")="25" %>
အားကစားအမျိုးအစားများ အားလုံး ဖတ်ရှုရန်
အောက်အရာများကို ဖတ်ရှုပါလိမ့်မည်:
<% Response.Cookies("user")("firstname")="Alex" Response.Cookies("user")("firstname")="John" Response.Cookies("user")("lastname")="Adams" Response.Cookies("user")("country")="UK" 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("
") next else Response.Write(x & "=" & Request.Cookies(x) & "
") end if response.write "" next %>