2012-05-09 34 views
0

怪怪所以下面的代碼工作完全在FirefoxCFcookie在不同的瀏覽器

<!--Cookies--> 
<cfset timer = createTimeSpan(0,3,0,0)> 
<cfcookie name = "user.ID" value = "#userID#" expires="#timer#">    <!--this will expire in three hours --> 
<cfcookie name = "user.Site" value = "#userSite#" expires="#timer#"> 
<cfcookie name = "user.Sess" value = "#userSess#" expires="#timer#"> 
<cfcookie name = "user.FName" value = "#userFName#" expires="#timer#"> 
<cfcookie name = "user.LName" value = "#userLName#" expires="#timer#"> 
<cfcookie name = "user.Email" value = "#userEmail#" expires="#timer#"> 
<cfcookie name = "user.SiteFirst" value = "#userSiteFirst#" expires="#timer#"> 
<cfcookie name = "user.RoundsTotal" value = "#userRoundsTotal#" expires="#timer#"> 
<cfcookie name = "user.RoundsCurrent" value = "#userRoundsCurrent#" expires="#timer#"> 

<!-- And now we send the user off to wait.cfm where they will wait ---> 
<!-- Users will not head to choose their picture choice ---> 

<script type="text/javascript"> 
    location.href='picChoice.cfm'; 
</script> 

在Firefox中,所有cookie中的值是完全通過。任何其他瀏覽器,所有的cookie都是空的。

希望有人能看到錯誤的地方,我不能。如果您想查看完整的cfm,請在此處輸入:http://pastebin.com/4G4wvjLd

+1

這是很多餅乾。你有沒有想過使用localStorage? –

回答

1

我認爲您有一個加載問題 - 在最終確定cookie操作之前瀏覽器已重定向。將你的location.href改爲一個cflocation,或者把它放在body「onLoad()」事件中(或者使用jquery的load事件來處理瀏覽器重定向的細微差別)。

+0

像魅力一樣工作謝謝你。 :) –

+1

太棒了!樂意效勞。 –

1

該代碼對我來說很合適。我在這裏運行它,使用cookie名稱作爲cookie值,例如並且cookie在IE和Chrome中正確設置並通過了。 Cookie規範中有一些漏洞(當天由Netscape編寫)導致某些瀏覽器在某些情況下做了些微不同的事情。 我推薦2件事:

1)簡化發送的值。在我的情況下,我使用cookie名稱作爲cookie值,它似乎工作。我會做同樣的測試,只是在picChoice.cfm中的cfdump#cookie#(這就是我在我的測試頁這裏所做的)

2)使用fiddler作爲代理運行請求並觀察瀏覽器是什麼獲取和發送,只是爲了確保您的代碼確實發送了set-cookie標頭並查看瀏覽器發送回服務器的內容。