setting a cookie

Gurpreet Singh Randhawa
Gurpreet Singh Randhawa used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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
> 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.
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

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>
You can essentially create any dimension (don't know the limit) by nesting the arrays instead.

<cfset a = arrayNew(3)>

<cfloop index="x" from="1" to="10">
  <cfloop index="y" from="1" to="10">
    <cfloop index="z" from="1" to="10">
        <cfset a[x][y]][z] = array(3)>
    </cfloop>
  </cfloop>
</cfloop>

The above will create a 3-D array at 1,000 different locations of the 3-D array "a"

So you can do this..

 a[x][y][z][1][1][1]

for every location where x,y,z are between 1 and 10

You can expand or change the range of 1 - 10 of course to other range if you needed.

So what I am saying is that although you can only create a 3-D array, you can create nested arrays and nested structures (an array within an array ora structure within an array) to a huge degree... I don't know the limit, but you will likely run out of memory.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial