asp如何设置httponly cookie

<%
'**************************************************
'ASP 中输出httponly cookie IE6.0以上浏览器支持
'WDFrog
'2009-04-15
'<meta http-equiv="Content-Type" content="text/html; charset=gb2312″>
'**************************************************
'———-SetHttpOnlyCookie—————————————-
'功能:设置HttpOnly Cookie
'参数:expDate 为保到期, 0表示不设置,设置为过去某一时间表示清除
'参数:domain 为空(string.Empty)表示不设置
'——————————————————————-
Function SetHttpOnlyCookie(cookieName,cookieValue,domain,path,expDate)
Dim cookie
cookie=cookieName & "=" & Server.URLEncode(cookieValue) & "; path=" & path
If expDate <> 0 Then
cookie=cookie & "; expires=" & DateToGMT(expDate)
End If
If domain <> "" Then
cookie=cookie & "; domain=" & domain
End If
cookie=cookie & "; HttpOnly"
Call Response.AddHeader ("Set-Cookie", cookie)
End Function
'————-getGMTTime————
'参数: sDate 需要转换成GMT的时间
'———————————
Function DateToGMT(sDate)
Dim dWeek,dMonth
Dim strZero,strZone
strZero="00″
strZone="+0800″
dWeek=Array("Sun","Mon","Tue","Wes","Thu","Fri","Sat")
dMonth=Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
DateToGMT = dWeek(WeekDay(sDate)-1)&", "&Right(strZero&Day(sDate),2)&" "&dMonth(Month(sDate)-1)&" "&Year(sDate)&" "&Right(strZero&Hour(sDate),2)&":"&Right(strZero&Minute(sDate),2)&":"&Right(strZero&Second(sDate),2)&" "&strZone
End Function
'示例
Call SetHttpOnlyCookie("cookieOnly1″,"onlyValue",".gyzs.com","/",0)
%>

来源:http://bbs.csdn.net/topics/390694124

加支付宝好友偷能量挖...


评论(0)网络
阅读(1135)喜欢(1)Asp/VBScript