Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hi, i ran into a problem today w

Status
Not open for further replies.

pru2k

Programmer
Joined
Mar 17, 2002
Messages
3
Location
GB
hi,

i ran into a problem today where a 'cfparam' value set with the 'cookie' scope was creating a persistent value. i thought that any variables created with 'cfparam' were strictly local and to write to a cookie required use of the 'cfcookie' tag. an example of the code is as follows:

== page1.cfm ==
Code:
<cfparam name=&quot;cookie.paul&quot; default=&quot;paul&quot;>
<a href=&quot;page2.cfm&quot;>Click Me</a>
== page2.cfm ==
Code:
the value of the cookie is: <cfoutput>#cookie.paul#</cfoutput>

i've looked at the cfparam / cfcookie documentation and can find no mention of this! can anyone point me to the correct page of the docs that mention this? i'm using CF4.5.

best wishes,

Paul Rushton
p.rushton@*nospam*.virgin.net

 
If you supply a default value, then if the variable does not exist it will create it. In this case, the variable was in the cookie scope, so it created it if it did not exist.

The same would hold true in other scopes, such as session, application, form, url, etc.

In the CFML Reference, in the CFParam tag, look under the usuage section:

Use cfparam with the name and default attributes to test for the existence of an optional variable. If the variable exists, processing continues and the value is not changed. If the variable does not exist, it is created and set to the value of the default attribute.


HTH,
Tim P.
 
hi tim,

thanks for your reply. what puzzled me was that by setting the CFPARAM with the cookie scope i was actually creating a persistent cookie that was accessible from other templates.

i know that using CFPARAM with the URL and FORM scope will only create a local variable unless it is passed to another template using a form or query string. i assumed that a variable created in cookie scope would 'die' on the template in which it was created!

best wishes

paul
 
Well a form or url variable will get &quot;lost&quot; if you move to another template (unless of course, you append that url or form variable to the page) In the case of a cookie variable, (or a client or session variable) it will persist across pages.

What I am not sure of is when the cookie will expire. My guess is that since there is no value set to the expires attribute of the cookie, then it will expire if you close the browser. (Just guessing here though).

HTH,

Tim P.
 
CFDUDE is correct. If you do not specify an expires attribute for a cookie it then becomes a browser cookie i.e. it lasts for as long as you have the browser open.


Kola
 
thanks for your help. a lesson learnt for me!

best wishes,

paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top