|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
缺点:正版成本价格贵(盗版就不说了)、不够安全,大多数服务器用windows系统,没有linux安全sessionDeletingaSubsetofSessionVariables
WhenusingSessionstostorevariablesin,Iuseanamingconvention-forexample,forallCustomerrelatedinfoIprefixthesessionvariablewiththesubstringCustomer.(sofortheCustomerIDitwouldbeCustomer.ID,thecustomerusernamewouldbeCustomer.Name,etc.)Thisisveryusefulwhenviewingthesessionobjectsasyoucanseetherelatedobjectsstraightoff.
TheproblemIhadtheotherdaywasthatIwantedtoremoveonlythoseitemsfromtheSessionwhichwereprefixedSW..SofirstoffIusedthefollowingcode:
---------------------------------------
Session("SW.1")="Test1"
Session("SW.2")="Test2"
Session("Other")="Other"
ForEachSessionIteminSession.Contents
IfLeft(SessionItem,3)="SW."then
Session.Contents.Remove(SessionItem)
endif
Next
---------------------------------------
Thisseemsfine,butwhenitsrun,whathappensisthatSW.1isremoved,butSW.2isNOTremoved.Why?Imnotexactlysure,butIguessthattheindexisthenresetsothatSW.2isnowwhereSW.1was,andseeingaswehaveiteratedpastthatitemintheForEach...Nextstatement,theloopjustmovestoOther,missingoutSW.2altogether!Eek!
SotogetroundthisIwrotethefollowingfunction,whichwillproperlydeleteallSessionvariablesthatbeginwithaspecifiedsubstring:
---------------------------------------
functionSessionRemoveSelected(sItemPrefix)
/////////////////////////////////////////////////
RemoveSelectedItemsstartingwithsItemPrefix
fromtheSession.e.g.SS.willremoveSS.IDand
SS.NAMEbutnotCustomerIDReturnsTrueorFalse
dependingonwhetheranyitemswhereremoved.
---------------------------------------
sItemPrefix[string]:ItemPrefix
/////////////////////////////////////////////////
dimarySession()
dimlCount,lPrefixLength
dimSessionItem
dimblnResult
lCount=-1
lPrefixLength=len(sItemPrefix)
blnResult=false
temporarilystoreinarrayitemstoremove
ForEachSessionIteminSession.Contents
ifleft(SessionItem,lPrefixLength)=sItemPrefixthen
lCount=lCount+1
redimpreservearySession(lCount)
arySession(lCount)=SessionItem
endif
Next
removeitems
ifIsArray(arySession)andlCount>=0then
forlCount=LBound(arySession)toUBound(arySession)
Session.Contents.Remove(arySession(lCount))
next
blnResult=true
endif
SessionRemoveSelected=blnResult
endfunction
-------------------------------------------------
</p>缺点:安全性不是太差了,还行,只要你充分利用系统自带的工具;唯一缺点就是执行效率慢,如何进行网站优化以后,效果会比较好。 |
|