1

I have the following function to set an administrator cookie when the rememberme button is checked:

<!--- setRememberMeCookie() Method --->
<CFFUNCTION NAME="setRememberMeCookie" ACCESS="REMOTE" RETURNTYPE="BOOLEAN" DISPLAYNAME="setRememberMeCookie" HINT="Saves user login details to cookie">
    <CFARGUMENT NAME="Usuario" TYPE="STRUCT" REQUIRED="YES">
    <!--- Save the struct to a cookie --->    
    <CFSCRIPT>
    adminStrc = Arguments.Usuario;
    getPageContext().getResponse().addHeader("Set-Cookie", "name=#adminStrc.Nombre#; value=#adminStrc.Valor#; SECURE=yes; Max-Age=31622400; DOMAIN=eMercado.com; path=/Cookies; httponly=true" );
    </CFSCRIPT>
    <CFRETURN true>    
</CFFUNCTION>

I am trying to test this function with the code below:

<CFSCRIPT>
usuarioCookie = "#application.UsuarioCookie#"; //My Cookies Component

adminCookie = structNew();
adminCookie.Nombre = "Admin_Clave";
adminCookie.Valor  = "2E372208-446D-57A5-07199C09B88DA458";

//To test the Cookie function
testCookie = usuarioCookie.setRememberMeCookie(adminCookie);
</CFSCRIPT>

<p><CFDUMP VAR="#testCookie#"> </p>

When I run the code I receive the following error:

Element VALOR is undefined in ADMINSTRC.

Could please let me know what I am doing wrong? Cheers.

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
  • Is there a reason you are not using the built in cfcookie tag? – M.Scherzer Apr 27 '14 at 12:25
  • What exact line of code is that error occurring on? I presume the `getPageCOntext()` call, but please always include the actual error message (copy and pasted from the screen), rather than just describing it. Put a try/catch around the erroring line, and dump out the struct in question when it errors: that should give you a clue what's going on. – Adam Cameron Apr 28 '14 at 05:58

1 Answers1

2

Just taking a stab here, but application scope is shared memory and within your function you are not explictly limiting the scope of adminStr to local.

perhaps confing the adminStr variable to local scope with the VAR keyword will resolve this issue.

Of course what could also be happening is that you have a cached old copy of your code in application scope. So that you are not actually running the code you think.

Best to test component within variables scope before caching it.

ohh and cfcookie is usually the way cookies are handled in cf, just in case you were not aware.

M.Scherzer
  • 921
  • 7
  • 9