Avatar of Coast Line
Coast Line
Flag 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
ColdFusion Language

Avatar of undefined
Last Comment
gdemaria

8/22/2022 - Mon
ComputerTechie

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
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)>
gdemaria

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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
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>
Coast Line

ASKER
here is an image
Untitled.png
gdemaria

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?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
gdemaria

> 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
gdemaria

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
Coast Line

ASKER
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
Your help has saved me hundreds of hours of internet surfing.
fblack61
Coast Line

ASKER
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#">
gdemaria

> 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
Coast Line

ASKER
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>
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
gdemaria

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question