Coldfusion形式的值到php setcookie()
我有一个Coldfusion页面,发布的表单值,我传递到php页面(通过cfhttp)。 Coldfusion代码示例:
I have a Coldfusion page with posted form values that I'm passing to a php page (via cfhttp). Example of the Coldfusion code:
<cfhttp method="Post" url="https://www.test.com/ssl/get_cookies.php" result="cookieResponse">
<cfoutput>
<cfif isdefined( "ppcid" )><cfhttpparam name="PPCID" type="formField" value="#session.ppcid#"></cfif>
<cfif isdefined( "cid" )><cfhttpparam name="CID" type="formField" value="#session.cid#"></cfif>
<cfif isdefined( "leadcomm" )><cfhttpparam name="LEADCOMM" type="formField" value="#LEADCOMM#"></cfif>
<cfif isdefined( "clk" )><cfhttpparam name="CLK" type="formField" value="#CLK#"></cfif>
<cfif isdefined( "dck" )><cfhttpparam name="DCK" type="formField" value="#DCK#"></cfif>
<cfif isdefined( "ccid" )><cfhttpparam name="CCID" type="formField" value="#CCID#"></cfif>
</cfoutput>
</cfhttp>
将这些值发布到get_cookie.php后,我想将这些值设置为Cookie。下面是我的get_cookies.php代码的示例:
After I post these values to get_cookie.php, I want to set these values as cookies. Here is an example of my get_cookies.php code:
setcookie("LEADCOM", getVariable('LEADCOMM'), time()+604800, "/", ".fha.com", 0);
setcookie("CCID", getVariable('CCID'), time()+604800, "/", ".fha.com", 0);
setcookie("QTR", getVariable('QTR'), time()+604800, "/", ".fha.com", 0);
setcookie("CLK", getVariable('CLK'), time()+604800, "/", ".fha.com", 0);
setcookie("DCK", getVariable('DCK'), time()+604800, "/", ".fha.com", 0);
FYI - getVariable是函数,用于$ _REQUEST PHP中的CF变量。我检查我的浏览器,我看不到这些cookie,即使我尝试重新访问该页面。任何建议?
FYI - getVariable is function to $_REQUEST the CF variable in PHP. I check my browser and I can't see these cookies, even when I try to revisit the page. Any Suggestions?
在上述示例的情况下,您可以将CFHTTP请求视为浏览器向PHP页面发出请求。您在PHP中设置的Cookie将返回到CFHTTP结果cookieResponse。在这一点上,他们仍然在服务器上,没有返回到初始客户端(一个称为CF页的开始)。如果您希望将这些设置为cookie到最终用户的浏览器,您需要使用ColdFusion再次设置它们。 这意味着您必须解析cookieResponse.header结果,找到cookie,您可以使用cookieResponse.responseHeader [SET-COOKIE]获取cookie并将其设置到最终用户的浏览器with cfheader
In the case of your example above, you can think of your CFHTTP request as the "browser" that is making a request to the PHP page. The cookies you are setting in PHP are being returned to the CFHTTP result "cookieResponse". At that point they are still on the server, nothing has been returned to the initial client (the one that called the CF page to start with). If you want those to be set as cookies at this point to the end user's browser you need to then set them again using ColdFusion. Which means you'd have to parse the cookieResponse.header result, find the cookies, You can get the cookies out using cookieResponse.responseHeader["SET-COOKIE"] and set them to the end user's browser with cfheader
像这样
<cfset cookies = cookieResponse.responseHeader["set-cookie"] />
<cfloop from="1" to="#structCount(cookies)#" index="i">
<cfheader name="SET-COOKIE" value="#cookies[i]#" />
</cfloop>