操作cookie
function1
<%
' ========================================================
' Cookies的操作函數
' ========================================================
' 儲存Cookie
Sub SaveCookie(CName, CKey, CValue, CExpires)
' CName : Cookie的名稱
' CKey : Cookie的鍵值
' CValue : Cookie的值
' CExpires : Cookie的過期日
If Len(CKey) = 0 Then
' 沒有Key的Cookie
Response.Cookies(CName) = CValue
Else
Response.Cookies(CName)(CKey) = CValue
End If
' 設定Cookie的時效
Response.Cookies(CName).Expires = Date + CExpires
End Sub
' 刪除Cookie
Sub DeleteCookie(CName)
' CName : Cookie的名稱
' 設定Cookie的時效屬性來刪除Cookie
Response.Cookies(CName).Expires = Date - 365
End Sub
' 取出Cookie
Function GetCookie(CName, CKey)
' CName : Cookie的名稱
' CKey : Cookie的鍵值
If Len(CKey) = 0 Then
' 沒有Key
GetCookie = Request.Cookies(CName)
Else
GetCookie = Request.Cookies(CName)(CKey)
End If
End Function
' ========================================================
%>
' ========================================================
' Cookies的操作函數
' ========================================================
' 儲存Cookie
Sub SaveCookie(CName, CKey, CValue, CExpires)
' CName : Cookie的名稱
' CKey : Cookie的鍵值
' CValue : Cookie的值
' CExpires : Cookie的過期日
If Len(CKey) = 0 Then
' 沒有Key的Cookie
Response.Cookies(CName) = CValue
Else
Response.Cookies(CName)(CKey) = CValue
End If
' 設定Cookie的時效
Response.Cookies(CName).Expires = Date + CExpires
End Sub
' 刪除Cookie
Sub DeleteCookie(CName)
' CName : Cookie的名稱
' 設定Cookie的時效屬性來刪除Cookie
Response.Cookies(CName).Expires = Date - 365
End Sub
' 取出Cookie
Function GetCookie(CName, CKey)
' CName : Cookie的名稱
' CKey : Cookie的鍵值
If Len(CKey) = 0 Then
' 沒有Key
GetCookie = Request.Cookies(CName)
Else
GetCookie = Request.Cookies(CName)(CKey)
End If
End Function
' ========================================================
%>
function2
<%
' ========================================================
' Cookies的操作函數
' ========================================================
' 儲存Cookie
Sub SaveCookie(CName, CKey, CValue, CExpires)
' CName : Cookie的名稱
' CKey : Cookie的鍵值
' CValue : Cookie的值
' CExpires : Cookie的過期日
If Len(CKey) = 0 Then
' 沒有Key的Cookie
Response.Cookies(CName) = CValue
Else
Response.Cookies(CName)(CKey) = CValue
End If
' 設定Cookie的時效
Response.Cookies(CName).Expires = Date + CExpires
End Sub
' 刪除Cookie
Sub DeleteCookie(CName)
' CName : Cookie的名稱
' 設定Cookie的時效屬性來刪除Cookie
Response.Cookies(CName).Expires = Date - 365
End Sub
' 取出Cookie
Function GetCookie(CName, CKey)
' CName : Cookie的名稱
' CKey : Cookie的鍵值
If Len(CKey) = 0 Then
' 沒有Key
GetCookie = Request.Cookies(CName)
Else
GetCookie = Request.Cookies(CName)(CKey)
End If
End Function
' ========================================================
%>
' ========================================================
' Cookies的操作函數
' ========================================================
' 儲存Cookie
Sub SaveCookie(CName, CKey, CValue, CExpires)
' CName : Cookie的名稱
' CKey : Cookie的鍵值
' CValue : Cookie的值
' CExpires : Cookie的過期日
If Len(CKey) = 0 Then
' 沒有Key的Cookie
Response.Cookies(CName) = CValue
Else
Response.Cookies(CName)(CKey) = CValue
End If
' 設定Cookie的時效
Response.Cookies(CName).Expires = Date + CExpires
End Sub
' 刪除Cookie
Sub DeleteCookie(CName)
' CName : Cookie的名稱
' 設定Cookie的時效屬性來刪除Cookie
Response.Cookies(CName).Expires = Date - 365
End Sub
' 取出Cookie
Function GetCookie(CName, CKey)
' CName : Cookie的名稱
' CKey : Cookie的鍵值
If Len(CKey) = 0 Then
' 沒有Key
GetCookie = Request.Cookies(CName)
Else
GetCookie = Request.Cookies(CName)(CKey)
End If
End Function
' ========================================================
%>
function3
<script Language="VB" Runat="Server">
' Cookies的操作函數
' 儲存Cookie
Sub addCookie(cName As String, cKey As String, cValue As String, cExpires As Double)
' cName : Cookie的名稱
' cKey : Cookie的鍵值
' cValue : Cookie的值
' cExpires : Cookie的過期日
If cKey.Length = 0 Then
' 沒有Key的Cookie
Response.Cookies(cName).Value = cValue
Else
Response.Cookies(cName)(cKey) = cValue
End If
' 設定Cookie的期限
Response.Cookies(cName).Expires = DateTime.Now.AddDays(cExpires)
End Sub
' 刪除Cookie
Sub deleteCookie(cName As String)
' cName : Cookie的名稱
' 設定Cookie的時效屬性來刪除Cookie
Response.Cookies(cName).Expires = DateTime.Now.AddDays(-365)
End Sub
' 取出Cookie
Function getCookie(cName As String, cKey As String)
' cName : Cookie的名稱
' cKey : Cookie的鍵值
Dim i As Integer
Dim cookie As HttpCookie
Dim cookies As HttpCookieCollection = Request.Cookies
' 找尋是否有此Cookie
For i = 0 TO cookies.Count - 1
cookie = cookies(i)
If cookie.Name = cName Then
If cKey.Length = 0 Then
' 沒有Key
Return Request.Cookies(cName).Value
Else
Return Request.Cookies(cName)(cKey)
End If
End If
Next
Return ""
End Function
' 顯示所有的Cookie資料
Sub showCookie(cName As String)
' cName : Cookie的名稱
Dim isFound As Boolean = False
Dim i, j As Integer
Dim cKey As String
Dim cookies As HttpCookieCollection = Request.Cookies
Dim cookie As HttpCookie
' 顯示所有的Cookie名稱
For i = 0 To cookies.Count - 1
cookie = cookies(i)
If cookie.Name = cName Then
isFound = True
Response.Write("Cookie名稱: " & cookie.Name & "<br>")
Response.Write("Expires期限: " & cookie.Expires.ToString() & "<br>")
Response.Write ("Domain網域:" & cookie.Domain & "<br>")
Response.Write ("Path路徑:" & cookie.Path & "<br>")
Response.Write ("Secure保密:" & cookie.Secure & "<br>")
If cookie.HasKeys Then
' 取得所有Cookie的Key值陣列
For Each cKey In cookie.Values
' 顯示Cookie值
Response.Write("<b>" & cKey & ": </b>" & cookie.Values(cKey) & "<br>")
Next
Else
Response.Write("Cookie值: " & cookie.Value & "<br>")
End If
Response.Write("<hr>")
End If
Next
If Not isFound Then
Response.Write("沒有找到Cookie: " & cName & "<br>")
End If
End Sub
</script>
' Cookies的操作函數
' 儲存Cookie
Sub addCookie(cName As String, cKey As String, cValue As String, cExpires As Double)
' cName : Cookie的名稱
' cKey : Cookie的鍵值
' cValue : Cookie的值
' cExpires : Cookie的過期日
If cKey.Length = 0 Then
' 沒有Key的Cookie
Response.Cookies(cName).Value = cValue
Else
Response.Cookies(cName)(cKey) = cValue
End If
' 設定Cookie的期限
Response.Cookies(cName).Expires = DateTime.Now.AddDays(cExpires)
End Sub
' 刪除Cookie
Sub deleteCookie(cName As String)
' cName : Cookie的名稱
' 設定Cookie的時效屬性來刪除Cookie
Response.Cookies(cName).Expires = DateTime.Now.AddDays(-365)
End Sub
' 取出Cookie
Function getCookie(cName As String, cKey As String)
' cName : Cookie的名稱
' cKey : Cookie的鍵值
Dim i As Integer
Dim cookie As HttpCookie
Dim cookies As HttpCookieCollection = Request.Cookies
' 找尋是否有此Cookie
For i = 0 TO cookies.Count - 1
cookie = cookies(i)
If cookie.Name = cName Then
If cKey.Length = 0 Then
' 沒有Key
Return Request.Cookies(cName).Value
Else
Return Request.Cookies(cName)(cKey)
End If
End If
Next
Return ""
End Function
' 顯示所有的Cookie資料
Sub showCookie(cName As String)
' cName : Cookie的名稱
Dim isFound As Boolean = False
Dim i, j As Integer
Dim cKey As String
Dim cookies As HttpCookieCollection = Request.Cookies
Dim cookie As HttpCookie
' 顯示所有的Cookie名稱
For i = 0 To cookies.Count - 1
cookie = cookies(i)
If cookie.Name = cName Then
isFound = True
Response.Write("Cookie名稱: " & cookie.Name & "<br>")
Response.Write("Expires期限: " & cookie.Expires.ToString() & "<br>")
Response.Write ("Domain網域:" & cookie.Domain & "<br>")
Response.Write ("Path路徑:" & cookie.Path & "<br>")
Response.Write ("Secure保密:" & cookie.Secure & "<br>")
If cookie.HasKeys Then
' 取得所有Cookie的Key值陣列
For Each cKey In cookie.Values
' 顯示Cookie值
Response.Write("<b>" & cKey & ": </b>" & cookie.Values(cKey) & "<br>")
Next
Else
Response.Write("Cookie值: " & cookie.Value & "<br>")
End If
Response.Write("<hr>")
End If
Next
If Not isFound Then
Response.Write("沒有找到Cookie: " & cName & "<br>")
End If
End Sub
</script>
ASP中操作COOKIE
'==============================================
' Cookies的操作函數
'==============================================
' 儲存Cookie
Sub addCookie(cName,cKey,cValue,cExpires)
' cName : Cookie的名稱
' cKey : Cookie的鍵值
' cValue : Cookie的值
' cExpires : Cookie的過期日
if cKey="" then
Response.Cookies(cName)=cValue
else
Response.Cookies(cName)(cKey)=cValue
end if
' 設定Cookie的期限
Response.Cookies(cName).
Response.Cookies(cName).Expires=now()+cExpires
End sub
' 刪除Cookie
Sub delCookie(cName)
' cName : Cookie的名稱
' 設定Cookie的時效屬性來刪除Cookie
Response.Cookies(cName).Expires=now()-365
End Sub
' 取出Cookie
Function getCookie(cName,cKey)
'cName : Cookie的名稱
'cKey : Cookie的鍵值
if cKey="" then
getCookie=Request.Cookies(cName)
else
getCookie=Request.Cookies(cName)(cKey)
END IF
End Function
'列出所有cookie
sub ListCookies()
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
end sub
'================================================
' Cookies的操作函數
'==============================================
' 儲存Cookie
Sub addCookie(cName,cKey,cValue,cExpires)
' cName : Cookie的名稱
' cKey : Cookie的鍵值
' cValue : Cookie的值
' cExpires : Cookie的過期日
if cKey="" then
Response.Cookies(cName)=cValue
else
Response.Cookies(cName)(cKey)=cValue
end if
' 設定Cookie的期限
Response.Cookies(cName).
Response.Cookies(cName).Expires=now()+cExpires
End sub
' 刪除Cookie
Sub delCookie(cName)
' cName : Cookie的名稱
' 設定Cookie的時效屬性來刪除Cookie
Response.Cookies(cName).Expires=now()-365
End Sub
' 取出Cookie
Function getCookie(cName,cKey)
'cName : Cookie的名稱
'cKey : Cookie的鍵值
if cKey="" then
getCookie=Request.Cookies(cName)
else
getCookie=Request.Cookies(cName)(cKey)
END IF
End Function
'列出所有cookie
sub ListCookies()
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
end sub
'================================================
//check是否打開cookie
function chk_cookie()
{
if (document.cookie=="")
{
alert("對不起,您的瀏覽器不支持COOKIE,請將此站設為可信任的站點.");
}
}
//<body onLoad="chk_cookie()">
function chk_cookie()
{
if (document.cookie=="")
{
alert("對不起,您的瀏覽器不支持COOKIE,請將此站設為可信任的站點.");
}
}
//<body onLoad="chk_cookie()">
申明
非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!
博文欢迎转载,但请给出原文连接。