使用coldfusion将id值存储在cookie中

时间:2010-07-15 17:49:45

标签: cookies coldfusion

寻找通过coldfusion跟踪cookie中最后5个产品ID的方法。每次访问产品页面时,我都会设置一个新ID。产品ID可以存储在逗号分隔列表中。我如何仅存储最后5个产品ID?

1 个答案:

答案 0 :(得分:2)

您可以尝试这样的事情(未经测试):

<cfset thisproductid = id_you_somehow_know_from_this_page>
<cfif not structkeyexists( cookie, 'mylist' )>
    <!--- no cookie? make one and set it to this ID --->
    <cfcookie name="mylist" value="#thisproductid#">
<cfelse>
    <cfif listlen( cookie.mylist ) eq 5>
        <!--- lifo --->
        <cfset cookie.mylist = listdeleteat( cookie.mylist, 1 )>
    <cfelse>
        <!--- check for odd conditions like listlen gt 5? up to you --->
    </cfif>
    <cfset cookie.mylist = listappend( cookie.mylist, thisproductid )>
</cfif>