Session in Coldfusion

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 eg <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, eg <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, eg 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 eg variables, local, etc.

链接地址: http://www.djcxy.com/p/60554.html

上一篇: 奇怪的cflocation行为:重定向到页面但不更新网址

下一篇: Coldfusion中的会话