Session in Coldfusion - session

Since the system I am using has Login and Logout feature, I am inside Session when I Logs in to the system. I am new to Session, my question is whatever variable and its value I have defined in any coldfusion page, would I be able to use it on any page?
For example, while going through the code of my system, I came across the following line one each and every CFML page:
<cfparam name="INPUTID" default="0">
and then later on somewhere in the page, I have seen this variable getting used like #INPUTId# .
Please clarify

To answer the question "whatever variable and its value I have defined in any coldfusion page, would I be able to use it on any page" ... that depends.
If you set a session variable e.g. <cfset session.foo = "bar" > then you can call #session.foo# on any page since it will be stored in the user's session.
However if you simply set a value, e.g. <cfset foo="bar" > then it will end up in the 'variables' scope and only available within that page, or request. (on that note, CF has a specific "request" scope, e.g. request.foo, which is for this purpose, available throughout any code that comes after the place where the value is set, in the same request or page view).
So, if you want to set values that can be used on other pages, use the session. But be careful, you will also need to use cfparam to set defaults, or use structKeyExists() to check for the value, before trying to call it from the user's session, since the value may not exist unless it has been set already. Otherwise, for values used in the same page, use the 'request' scope, or see the CF docs for other scopes e.g. variables, local, etc.

Related

How to save a specific variable into session with "expire_on_close" = true in Laravel?

I know how to change laravel configuration in order to expire all session variables on close but I want to do this only for one variable and I want all other variables to remain in the browser on close!
I have searched a lot without any chance!

UrlReferrer VS Session VS Query Parameter

I have 2 search-pages and 1 result-page.
The result-list on the result-page is a list of URLs.
The URLs are dependent of the search-page, so if the user comes from search-page1 he gets a different URL to the user who comes from search-page2.
So on the result-page I have to know from which search-page the user comes.
First I tried it with UrlRefferer, but if the result-list has too many results, I use paging and if the user clicks on the second result-list I loose the UrlReferrer...
What is the best way to do this? To use Session or better use a query parameter in the URL?
If I understood your question, this is only for a single request. So better you can pass as a request parameter. Session will unnecessary hold the value for the whole pages which is not appropriate. And unless you update the value in session parameter, it will keep hold the old value only.
Is it possible for you to hold the value in a script variable?
IMHO session is a simpler solution, so you doesn't have to set query parameters every time user change page.

How do you pass unchecked checkbox value using Coldfusion.ajax.submitform?

I'm stumped. I have a <cfform> and I'm saving the form info to a database using a cfc and Coldfusion.Ajax.submitform. My form uses checkboxes. What I can't seem to figure out is how to capture if a checkbox is unchecked. I've read that if a checkbox is unchecked, it doesn't get sent with the form info. I've also read that you can use <cfparam> to give the checkbox a default value so that if the checkbox is unchecked, it will still have a value e.g. <cfparam name="form.checkbox1" default="0">. Unfortunately, it doesn't seem to work when I use ColdFusion.Ajax.submitForm. Any insight would be greatly appreciated. Thanks.
Creating a proper answer so you can close this question.
Per the ColdFusion documentation: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7faf.html
Cfparam tests for the existence of a parameter (that is, a variable),
validates its data, and, if a default value is not assigned,
optionally provides one.
Mostly it's just used to create a default value for a variable of pretty much any scope.
As you have discovered, the cfparam tag must be used when the variable is required, in the processing page. cfquery param creates the variable in memory on the coldfusion server and is only available for the duration of the request (unless you use it to set a value to a persistent scope like session or application). It does not create form elements or javascript variables

Setting Absolute Uri in MVC 3

Is it possible to set the absoluteURI in the controller after clicking on an action link? So for example:
User clicks on a link called "GoHere". The current URL is domain.com/section/place. When the link hits the method in the controller, it recognizes that the user is currently in a section called "section", even though in the file structure section doesn't exist. The link itself actually points to domain.com/place2. Instead of returning a URL of domain.com/place2, it returns domain.com/section/place2.
The reason I ask is because for what I'm doing, the section is completely arbitrary and doesn't exist. It's just there to give the impression that the user is in another section. I know I could create extra sets of controllers, but I'm trying to get around this since for management purposes it's better if I just have one set of controllers. Is this possible? Thanks.
In your gobal.asax, try setting your route to require section for the control. Maybe "{control}/section/{action}/" and whatever else you need.

How to set a value into a cookie or session in Drupal

I am working on a friend reference function, so I pass the user id through the url like this:
www.example.com?fid=22
I need to set this as a session or cookie with access to all modules in Drupal 6.
If i set the session it returns for the particular module. Setting the cookie is not working at all.
$user->new_property works only on the particular page where it is set, if I move to another page there is no new_property in $user variable object list.
If you want to save a variable in a users session, you can in Drupal (PHP) use the super global varaible $_SESSION.
$_SESSION['fid'] = $_GET['fid'];
The above code is an example of how this could be done.
Since you are getting the info from the URL the user can change it as his whim. So be careful what you use such data for and never trust it blindly. It could become anything, as the user always freely can alter the url any way he want.

Resources