Coldfusion StructDelete creates blank value - cookies

I'm using Codlfusion 9's StructDelete() method to remove a value from a cookie. But after using
StructDelete(cookie,"selector12")
I'm getting a value of [empty string] for cookie.selector12 despite deleting it
This is the code I'm using:
<cfdump var="#cookie#">
<!--- kill any existing selector cookie when looking at a profile --->
<cfset structDelete(cookie,'selector#URL.clk#')>
<cfdump var="selector#URL.clk#">
<cfdump var="#cookie#">
To give the following output:
Does StructDelete actually just set blank values? Or have I missed something obvious and simple... again

The behavior of StructDelete() when applied to the COOKIE structure pushes the following header to your browser:
Set-Cookie SELECTOR12=;expires=Wed, 14-Dec-2011 10:06:02 GMT;path=/
which in turn will (for the remainder of the life of that request) produce a browser cookie with a blank value -- which mimics the behavior you're seeing when calling cfdump on that COOKIE structure.
This is simply a side-effect of dealing with the COOKIE structure, which in reality, wraps access to your browser's cookies--and is therefore limited by how cookies are defined/managed in web-browsers.

Related

Error switching to client management

This is embarrassing. I've been a ColdFusion developer for 13 years and I've never had a reason to use client management over session management. Anyway, I've set up a database and datasource in CFAdmin, then selected that datasource as the default storage mechanism for client sessions.
Then I went through all my code and global-replaced all my session scopes with clients scope.
Top of my application.cfm looks like:
<CFAPPLICATION
NAME="blah"
SESSIONMANAGEMENT="No"
SESSIONTIMEOUT=#CreateTimeSpan(0,2,0,0)#
CLIENTMANAGEMENT="Yes"
CLIENTSTORAGE="sys_blah"
>
In my application.cfm, I had previously set a few variables globally related to session authentication, i.e.
<cfparam name="session.user.authenticated" default="0">
<cfparam name="session.user.id" default="">
However, now that these are written as
<cfparam name="client.user.authenticated" default="0">
<cfparam name="client.user.id" default="">
I get an error:
Element USER is undefined in CLIENT.
What might I be doing wrong?
I can see the client vars going into the newly-created database.
I'm on CF12
Client variables must be simple data types: strings, numbers, lists,
Booleans, or date and time values. They cannot be arrays, recordsets,
XML objects, query objects, or other objects. If you must store a
complex data type as a client variable, you can use the cfwddx tag to
convert the data to WDDX format (which is represented as a string),
store the WDDX data, and use the cfwddx tag to convert the data back
when you read it. For more information on using WDDX, see Using WDDX.
http://help.adobe.com/en_US/ColdFusion/10.0/Developing/WSc3ff6d0ea77859461172e0811cbec0c35c-7fd5.html
So... WDDX or JSON would work.

What is wrong with this CFIF structure?

I have the following at the top of a page...
<cfif isdefined("session.loggedin") and session.loggedin eq true>
<cfinclude template="includeUserInfo.cfm">
<cfinclude template="includeSideBar.cfm">
<cfelse>
<cflocation url="../sign-in.cfm">
</cfif>
When I execute the page and session.loggedin DOES equal true it executes as expected and adds the included files.
If I hit the page without logging in - I'm not being redirected to the sign in page - I'm just getting a completely blank page - zero html in the view source.
Session management is enabled in my application.cfc file
I'm not sure if what I am doing is wrong - appreciate any advice.
OK - so (as is often the case) I had missed the underlying cause of the problem - and while focussing on the imagined problem with the CFIF statement itself, missed the small cfinvoke that was before it in the code. That was trying to execute a database lookup, but failing when a user was not logged in.
swapping these around and making sure the block above is before everything else on the page has done the trick. Go me. Thanks everyone for the input.

How do you acquire the rewritten CFWheels URL of an given page?

CFWheels has the URLFor() function for getting the internal URL based on supplied arguments. Is there a way to get the internal URL without supplying any arguments?
For example:
Given a user navigates to "http://somedomain.com" or "http://somedomain.com/about/" or "http://somedomain.com/contact/" is there a method like ReWrittenURL() that returns something like "/" or "/about/" or "/contact/"?
Using URLFor() with no arguments returns "/home/index" or "/about/index" or "/contact/index".
CGI.SCRIPT_NAME returns "/rewrite.cfm"
Obviously with Javascript using document.location.href I can get what I'm after.
Does CGI.path_info have the value you're looking for?
edit
At first, I deleted this post, being utterly confounded. Now I've done a little test - I downloaded the latest wheels core files (1.1.6), extracted to an IIS 7.5 (with URL Rewrite module installed) + CF9 webserver, and edited the "web.config" file in the core root, setting "enabled='true'" for the rewrite rule. Also, since I was running this example from a subfolder, I changed the path from "/rewrite.cfm" to just "rewrite.cfm". This got me to the point where I was able to successfully requests urls like this:
http://server/wheelstest/wheels/wheels
From here, I edited the layout.cfm under views/wheels, adding:
<cfdump var="#cgi#">
When I then request the above URL (/wheelstest/wheels/wheels), I see the dump for the cgi scope. Under path_info, this is the value: /wheels/wheels.
Next, I added a blank "index.cfm" file under views/wheels.
When I request /wheelstest/wheels, I get this for path_info: "/wheels".
When I request /wheelstest/wheels/, I get this for path_info: "/wheels/".
When I request /wheelstest/wheels/index, I get this for path_info: "/wheels/index".
When I request /wheelstest/wheels/index/, I get this for path_info: "/wheels/index/".
So basically - cgi.path_info is doing for me exactly what you describe you want. What is different about your setup than mine, such that it isn't returning that value for you?
there might be a better way to do this... but here I go anyway
every page gets sent the #params#
<cfdump var="#params#">
<cfoutput>#params.action#/#params.controller#/#params.key#</cfoutput>
<cfabort>
try putting that in a controller and see the results
the problem is that if the objects inside the params object don't exist you get an error. So the path that gets generated needs to check if the struct key exists and edit accordingly.
CGI.Path_Info will give you the desired results. I've been trying different options however they all failed and went into the redirect loop. As soon as I switched CGI.path_info it all started well.

Can we pass a whole Structure over an URL?

I am opening a new popup window on click of an URL in my page.
My question over here is Can i pass whole structure to the new page ?
If thats not possible is there any simple method to do that ?
Is the page being opened in the URL part of the same application?
If so a better way would be to save the structure in the user's session and pull in the information in that way. Cleaner URLs, code and more secure.
Cheers,
James
Expanding on James Buckingham's answer...
(This assumes you have session management set to true.)
In the calling page, simply copy your structure to a session variable:
<cfset session.myTempStruct=variables.myTempStruct />
Then, in the popup, copy the structure back to the local scope for that request:
<cfset variables.myTempStruct=session.myTempStruct />
If you don't want that structure to hang around in the session, you can have the request for the popup remove it from the session right after copying it to the local scope.
<cfset structDelete(session, "myTempStruct") />
Although HIGHLY NOT recommended, you could do this:
<cfset tmp = {} />
<cfset tmp.name="Marcos" />
<cfset tmp.lname="Placona" />
<cfwddx action="cfml2wddx" input="#tmp" output="tmpWDDX">
link
If you decide to take this approach, I'd suggest sending the information via form as opposed to URL.
You always have the option to store the data in a persistent object such as a bean, or a more simple approach such as a session.
Hope this helps you
You can add your data points as parameters to the end of the URI, but I do not suggest using the method you see as it would be highly subject to injection.
Serializing Struct (with serializeJSON() or something) and puttin git in URL seems reasonable in case struct is not too big (read: less than 3-4k characters in total).
Other solution would be to put this in some shared scope: session, application etc.
Third, would be to call cfm with POST request which can handle larger structs then GET.

used structdelete and now Elementemployee.id is undefined in SESSION

using coldfuion 9
I used structdelete(session,"Elementemployee.id") in one of my .cfm display files.Also
in my application.cfc it defined as is
<cfset tArray[1][2] = "#session.employee_id#">
and the error is
`Elementemployee.id is undefined in SESSION.`
Is there a way that i can reset it without following the method shown below
Navigate to the page Server Settings => Memory Variablesin the Coldfusion Administrator. Uncheck the option Use J2EE session variables and check the options Enable Application Variables and Enable Session Variables. Click the button to submit the changes.
I'm not sure what your intent is. If you delete it, you are explicitly making it undefined.
Maybe you mean to set it to zero or the empty string, as in one of these?
<cfset session.employee_id = 0>
<cfset session.employee_id = ''>
Does that help?
Not quite sure what you're asking, but if you're trying to delete session.elementEmployee.id, try this:
<cfset StructDelete(session.elementEmployee, "id") />