Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Date Date
Qty:
Subtotal
Promotions
Estimated Shipping
VAT
Calculated at checkout
Total
Checkout
ColdFusion Help / 

Missing session variables when using the cflocation tag

Adobe Community Help


Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

Issue

Setting Session variables on a CFML template that uses thecflocation tag may prevent session variables from being set. This article describes several causes for this behavior and several workarounds for the problem.

Developers who use session variables may find that some customers on their web site experience "lost sessions." When this occurs, the page generates an error message similar to the following:

An error occurred while evaluating the expression: #session.var1# Error resolving parameter SESSION.VAR1 The session variable VAR1 does not exist.

This error can be caused by one of the following:

  • Your session variables are not properly locked with thecflock tag.



    For more information on locking, refer to ColdFusion Locking Best Practices.
  • You are setting session variables on the same CFML template where you are using the cflocation tag.



    Note: In this instance, some customers can browse your web site with no error message, while other customers experience the error message (as shown above). The key difference between those who receive these errors and those who do not depends on whether the user has visited another page in your web site where a CFID or CFToken cookie was assigned to him/her.

The scenarios below illustrate the error.

Scenario 1

A new user visits your web site and requests her first page, Firstpage.cfm. Firstpage.cfm sets a session variable and then uses the cflocation tag, as follows:

<cflock TYPE="EXCLUSIVE"       SCOPE="SESSION"><cfset session.var1 = "Bob"></cflock><CFLOCATION    URL="http://mysite.com/secondpage.cfm"    ADDTOKEN="No">
  1. Application.cfm processes.



    In the cfapplication tag, settingSessionManagement="Yes" andSetClientCookies="Yes" creates the CFID/CFToken cookies.
  2. Firstpage.cfm sets the session variable, var1 and binds it to the CFID/CFToken session initiated by the Application.cfm file.
  3. The error occurs because the CFID/CFToken cookies are not passed to the browser. Instead, the cflocation tag redirects the request to a new page (for this example, it redirects to a page called secondpage.cfm).



    Important note: Cookies are not passed between server side redirections--in this case by using the cflocation tag. Cookies are passed either from the browser to the webserver to the ColdFusion Server, or when they are first set, from the ColdFusion Server to the webserver to the browser.
  4. Before secondpage.cfm processes, however, Application.cfm processes again. Since the CFID/CFToken cookies never made it to the browser, they are not part of the request for secondpage.cfm.



    Therefore, when the cfapplication tag is processed (for the second time), it assigns a new CFID/CFToken to the request. This new CFID/CFToken is not associated with the initial session variable set in Firstpage.cfm.



    Therefore, if secondpage.cfm tries to read the session variable, it will be undefined and throw an error message. Also note that if secondpage.cfm returns an "undefined session variable" error to the user, the error message will not include the CFID/CFToken cookies with that error. ColdFusion does not return cookies when an error is generated.

Scenario 2

In this scenario, your customers intermittently experience the "undefined session variable" error message. In some cases, a returning user who has already been assigned a CFID/CFToken cookie from another CFML template in your application does not experience the error message. This is described in the the following scenario.

  1. Application.cfm processes.



    Since the request includes CFID/CFToken cookies already received from another template in your web site, the request passes the existing CFID/CFToken cookies. ColdFusion recognizes the CFID/CFToken cookies, and therefore the cfapplication tag does not assign a new CFID/CFToken.
  2. Firstpage.cfm processes and sets the session variable bound to the existing CFID/CFToken.
  3. The cflocation tag processes and redirects to secondpage.cfm.
  4. Before secondpage.cfm processes, Application.cfm processes again.



    When the cfapplication tag processes (for the second time), it recognizes the existing CFID/CFToken cookies passed with the request.



    Therefore, the cfapplication tag does not assign a new CFID/CFToken. If secondpage.cfm tries to read the session variable, it can read the session variable without error because the same CFID/CFToken is in effect during this read; the same as the initial session variable that was set.
To the top

Solution

There are several possible workarounds to this issue, as follows.

  1. Set AddToken="yes" in the cflocation tag.



    Setting AddToken="Yes" will append the CFID and CFToken values to the URL of the redirected request. ColdFusion will recognize these CFID and CFToken URL parameters and will not assign new CFID and CFToken values. The session variables are available to the second template.



    Before using this solution, you should be aware that passing CFID and CFToken as URL parameters can be a security risk. For more information please see Security Best Practice: URL Session Variables and HTTP_REFERER.
  2. Instead of using server-side redirection with thecflocation tag, consider using one of several methods for client-side redirection.



    Client-side redirection allows the CFID and CFToken cookies assigned with the first request to be passed on to the browser. After the browser has received the results of the first request, it is instructed to request a second page from the server. The CFID and CFToken cookies it received from the first request will be passed along with the second request.



    Some examples of client-side redirection are as follows:



    • Use the HTML meta tag, as follows:



      <meta http-equiv="Refresh" content="0;url=http://mysite.com/secondpage.cfm">
    • Use two cfheader tags, as follows:



      <CFHEADER STATUSCODE="302" STATUSTEXT="Object Temporarily Moved"><CFHEADER NAME="location" VALUE="http://mySite.com/secondpage.cfm">
    • Use JavaScript, as follows:



      <script LANGUAGE="JavaScript"> window.location="secondpage.cfm";</script>
  3. Consider using a third-party alternative tocflocation written to workaround this problem.



    ColdFusion custom tags typically use some method of client-side redirection and add additional functionality. Some of these alternatives are available at the Macromedia ColdFusion Exchange.



    Note that third-party custom tags are not supported by Macromedia ColdFusion support.
  4. Consider if your application logic will permit you to use thecfinclude tag instead of the cflocation tag.
To the top

Additional Information

  • ColdFusion Locking Best Practices
  • Security Best Practice: URL Session Variables and HTTP_REFERER
Keywords: tn_18171

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement