开发者

Store id values in cookie with coldfusion

Looking for a way to track the last 5 product ids in a cookie via coldfusion. I'll set a new id each time a product page is visited. The produc开发者_如何学Ct ids could be stored in a comma separate list. How would I store only the last 5 product ids?


You could try something like this (untested):

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜