Link to home
Start Free TrialLog in
Avatar of Coast Line
Coast LineFlag for Canada

asked on

setting a cookie

Now I am changing some Old Code which is using Application.cfm File, No such logic is written which should actually expire the cookie if set to expire when browser closes.

Now i am doing a login, i want to set a cookie or session alive even after user closes his/her browser, well i will provide a warning Mesage if they check the checkout, they have to logout explicity, well just guide a bit, i know that could be done with cfcookie but more on better secure way that would be great

Thanks

Also, Guy Asked me how to create Multidimensional Array in Coldfusion

Anyone, My Way was like <cfset a = Arraynew(3)>
<cfset a[1][1][1] = arraynew(3)>

anyone else can try other way

Cheers
Avatar of ComputerTechie
ComputerTechie
Flag of United States of America image

This should help with your cookie issue. i prefer session over cookie.

http://www.learn-coldfusion-tutorial.com/SessionApplication.cfm

also here an example if a multidimensional array:

http://www.informit.com/articles/article.aspx?p=31765&seqNum=8

CT
Avatar of gdemaria
> i want to set a cookie or session alive even after user closes his/her browser

Sessions will stay in effect even after you close the browser, unless you are using jsession which will terminate after the browser closes.

For a cookie, use an expiration date however long you need 1 day, 3 days, Never.

>  know that could be done with cfcookie but more on better secure way that would be great

A more secure way would be not to do it.    If your use closes his browser, you should assume he will not be logged in when he returns.  However, if your site has low security needs, you can keep him logged in with an encrypted cookie.  But when the user goes to the account area make sure you ask for his login...  So, if he was "automatically" logged in when he came to the website, you need to ask for a login before he does anything like see his profile or buy something.




This is correct
<cfset a = Arraynew(3)>


This is not correct
<cfset a[1][1][1] = arraynew(3)>
One more comment on the 3-D array.   I find that in most cases, people really don't want a multidimensional array, but really need an array of structures instead.  Or even nested structures.

Which is more friendly?

 #product[3][2][5]#

or

 #product[1].size.color#   or    #product.shirt.size.color#

Of course there are uses for 2-D and 3-D arrays, but I find most of the time, it's better to use a name than a number when setting up these types of elements.
Avatar of Coast Line

ASKER

u said this is incorrect

<cfset a[1][1][1] = arraynew(3)>

but i tested it and it works

<cfset a= arrayNew( 3)>
<cfset a[1][1][1] = arrayNew( 3)>
<cfset a[1][1][1][1][1][1] = "this is a test" >
<cfoutput> #a[1][1][1][1][1][1]# </cfoutput>
here is an image
Untitled.png
It is not correct because you wanted a 3-D array, this creates a 6-D array

<cfset a[1][1][1] = arraynew(3)>

<cfoutput> #a[1][1][1][1][1][1]# </cfoutput>



This creates a 3-D array
<cfset a= arrayNew( 3)>

If you want a 6-D array, do this..

<cfset a= arrayNew(6)>

I am interested in how this will be used, do you know?
> Also, Guy Asked me how to create Multidimensional Array in Coldfusion

Sorry, I misread the question.  I thought you wanted a 3-D array.

Simply do this..

<cfset a= arrayNew( X )>

where X is the number of dimensions
Note, if you do it this way...

<cfset a[1][1][1] = arraynew(3)>

This will probably give an error..

<cfoutput> #a[1][1][2][1][1][1]# </cfoutput>

Because you are creating a 3-D array only at location a[1][1][1]  not at any other element
so if u are saying >> <cfset a= arrayNew( X )>

where X is the number of dimensions

i went for 100

then what ?


is there any limit in coldfusion for creating
this is what i get

The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
Array dimension 100 must be between 1 and 3.

 
The error occurred in C:\inetpub\wwwroot\myproject\array.cfm: line 7
7 : <cfset b = ArrayNew(100)>
8 : <cfdump var="#b#">
> Array dimension 100 must be between 1 and 3.

I guess your limit is a 3-D array

of course you can nest an array or structure inside of another array, like you did here..

<cfset a[1][1][1] = arraynew(3)>

But keep in mind this does not create a 6-D array, it creates a 3-D array at location [1][1][1] ONLY.

But remember, IMO, it's better to nest structures
yeah agreed, but someone was just arguing with me that coldfusion can be multidimensional in sense that even i pass X as 6, it will work, so oractically it holds 3d array only, not multidimensional

also, 6d array is created but cannot be used far anough, it will always work as:

<cfoutput> #a[1][1][1][2][3][1]# </cfoutput>
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial