似乎无法在cfscript中设置cookie的过期日期。有什么提示吗?顺便说一下,这是ColdFusion 9。
似乎无法在cfscript中设置cookie的过期日期。有什么提示吗?顺便说一下,这是ColdFusion 9。
<cfscript>
的等价物 <cfcookie>
仅提供Cookie作用域内存变量的直接赋值。您无法使用直接赋值来设置持久化cookie,这些cookie存储在用户系统上。因此,如果您想使用脚本编写的 CFML 设置永久性 cookie,您将需要编写一个包装函数。
我写了这个UDF。注意,它的httpOnly属性只适用于CF9,所以如果你使用的是CF8,你需要将其移除。
<cffunction name="setCookie" access="public" returnType="void" output="false">
<cfargument name="name" type="string" required="true">
<cfargument name="value" type="string" required="false">
<cfargument name="expires" type="any" required="false">
<cfargument name="domain" type="string" required="false">
<cfargument name="httpOnly" type="boolean" required="false">
<cfargument name="path" type="string" required="false">
<cfargument name="secure" type="boolean" required="false">
<cfset var args = {}>
<cfset var arg = "">
<cfloop item="arg" collection="#arguments#">
<cfif not isNull(arguments[arg])>
<cfset args[arg] = arguments[arg]>
</cfif>
</cfloop>
<cfcookie attributecollection="#args#">
</cffunction>
<cfscript>
if(!structKeyExists(cookie, "hitcount")) setCookie("hitcount",0);
setCookie("hitcount", ++cookie.hitcount);
setCookie("foreverknight",createUUID(),"never");
</cfscript>
<cfdump var="#cookie#">