Ask a Question related to Coldfusion - Getting Started, Design and Development.
-
Jean Genie #1
Cannot set session variable
I created a simple login script a some time ago which worked like a charm until
I recently switched to a new web host that's running ColdFusion MX. The form
submits to a "login2.cfm" script which checks the entered username and
password against the database and either passes them back to the form with a
"wrong u&p - please try again" message, OR sets a session ID or cookie
(whichever will be accepted/created on their computer) and sends them to a
landing page where their key information is pulled from the database and
displayed:
<cfquery name="GetUser" datasource="clientsupport">
SELECT *
FROM Company
WHERE UserName = '#form.UserName#'
AND Password = '#form.Password#'
</cfquery>
<!--- Check if we have a winner! --->
<cfif GetUser.RecordCount gt 0>
<!--- Store the user id in a session variable and cookie. --->
<cfset Session.userID = GetUser.CompanyID>
<cfcookie name="ID" value="#GetUser.CompanyID#">
<script>
location.href="../../Pages/contacts/acctcontacts.cfm"
</script>
<cfelse>
<!--- ie If user does not exist --->
<!--- Pass the variables back in the URL - message and UserName --->
<cfset loginpage = "/Support/supportintro.cfm?Message=" &
URLEncodedFormat("Invalid User Name/Password Combination - please reenter")>
<cfset loginpage = loginpage & "&UserName=" &
URLEncodedFormat(#Form.UserName#)>
<cflocation url="#loginpage#">
</cfif>
I know the connection to the database is fine because if I enter a bogus u&p,
it sends them back to the form with the "try again" message. I am assuming
that issue is the session ID not being set because when I get to the landing
page it says:
Element USERID is undefined in SESSION.
The error occurred in
D:\inetpub\vhosts\techtrack.com\httpdocs\Support\P SSP\Pages\contacts\acctcontact
s-info.cfm: line 21
19 : SELECT * from Company INNER JOIN SYSTTSIEmployees
20 : ON Company.TTSIEmployeeID = SYSTTSIEmployees.TTSIEmployeeID
21 : WHERE CompanyID = #Session.userID#
22 : </cfquery>
23 :
Please try the following:
* Check the ColdFusion documentation to verify that you are using the
correct syntax.
* Search the Knowledge Base to find a solution to your problem.
Browser Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10)
Gecko/20050716 Firefox/1.0.6
Remote Address 24.82.160.143
Referrer [url]http://www.techtrack.com/Support/PSSP/Login/login_client/login2.cfm[/url]
Date/Time 25-Oct-05 04:50 PM
Stack Trace
at
cfacctcontacts2dinfo2ecfm1025299766.runPage(D:\ine tpub\vhosts\techtrack.com\http
docs\Support\PSSP\Pages\contacts\acctcontacts-info.cfm:21) at
cfacctcontacts2ecfm1326185909.runPage(D:\inetpub\v hosts\techtrack.com\httpdocs\S
upport\PSSP\Pages\contacts\acctcontacts.cfm:2)
coldfusion.runtime.UndefinedElementException: Element USERID is undefined in
SESSION.
at coldfusion.runtime.CfJspPage.resolveCanonicalName( CfJspPage.java:1054)
at coldfusion.runtime.CfJspPage._resolve(CfJspPage.ja va:1031)
at coldfusion.runtime.CfJspPage._resolveAndAutoscalar ize(CfJspPage.java:1130)
at
cfacctcontacts2dinfo2ecfm1025299766.runPage(D:\ine tpub\vhosts\techtrack.com\http
docs\Support\PSSP\Pages\contacts\acctcontacts-info.cfm:21)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java :152)
at coldfusion.tagext.lang.IncludeTag.doStartTag(Inclu deTag.java:343)
at coldfusion.runtime.CfJspPage._emptyTag(CfJspPage.j ava:1908)
at
cfacctcontacts2ecfm1326185909.runPage(D:\inetpub\v hosts\techtrack.com\httpdocs\S
upport\PSSP\Pages\contacts\acctcontacts.cfm:2)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java :152)
at coldfusion.tagext.lang.IncludeTag.doStartTag(Inclu deTag.java:343)
at coldfusion.filter.CfincludeFilter.invoke(Cfinclude Filter.java:65)
at coldfusion.filter.ApplicationFilter.invoke(Applica tionFilter.java:210)
at coldfusion.filter.RequestMonitorFilter.invoke(Requ estMonitorFilter.java:51)
at coldfusion.filter.PathFilter.invoke(PathFilter.jav a:86)
at coldfusion.filter.ExceptionFilter.invoke(Exception Filter.java:50)
at
coldfusion.filter.ClientScopePersistenceFilter.inv oke(ClientScopePersistenceFilt
er.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilt er.java:38)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilt er.java:38)
at coldfusion.filter.DatasourceFilter.invoke(Datasour ceFilter.java:22)
at coldfusion.CfmServlet.service(CfmServlet.java:105)
at coldfusion.bootstrap.BootstrapServlet.service(Boot strapServlet.java:78)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker. java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvok erChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequ estDispatcher.java:257)
at jrun.servlet.ServletEngineService.dispatch(Servlet EngineService.java:527)
at
jrun.servlet.jrpp.JRunProxyService.invokeRunnable( JRunProxyService.java:204)
at
jrunx.scheduler.ThreadPool$DownstreamMetrics.invok eRunnable(ThreadPool.java:349)
at
jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRu nnable(ThreadPool.java:457)
at
jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeR unnable(ThreadPool.java:295)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java :66)
I'm wondering if MX does things differently and if that's why the script no
longer works. Does anyone know why this might be happening? Sorry for the
long post, and thanks for taking a look!
Jean Genie Guest
-
#39634 [NEW]: session variable and normal variable
From: erhanbaris at gmail dot com Operating system: Win Xp SP1 PHP version: 5.2.0 PHP Bug Type: Variables related Bug... -
session variable and IE
Hi there, I have a session variable that holds an user name, after user logs in. All works just fine in development environment (Intranet) for IE... -
Session Variable in IIS 5
Hi, i can't use a Session variable in IIS 5, when i try to assign a value send to me next erro messages "Microsoft VBScript runtime (0x800A000D)... -
Datalist - how (if) to use a sub variable or session variable in the footer?
Hi, sorry to be greedy with all my posts lately, but can you tell I'm doing new things this week? I've just done my first datalist (a simple... -
[SESSION] Session variable deleted prior to command?
Hi all, I'm developing a database system on my local computer (OS/version details at bottom) with a simple user authentication using sessions. On... -
Kronin555 #2
Re: Cannot set session variable
Are you enabling session variables in your <cfapplication> tag?
Kronin555 Guest
-
jiggar #3
Re: Cannot set session variable
try enclosing "cfset" of the session variable in "cflock" tags, kinda like this:
<cflock timeout="100" scope="session" type="exclusive">
<cfset session.mysession = "cookie">
</cflock>
jiggar Guest
-
Jean Genie #4
Re: Cannot set session variable
Sorry guys! When I submitted I got a Java error which is why I submitted more than once. Pls ignore first 3 of 4 replies! <:-o
Jean Genie Guest
-
Kronin555 #5
Re: Cannot set session variable
You said you switched hosts... are they on Linux? if so, is your
application.cfm file named "Application.cfm"?
Linux and Solaris environments are case-sensitive, so you need to ensure your
Application.cfm is named with the correct case (otherwise it will be ignored).
Kronin555 Guest
-
Jean Genie #6
Re: Cannot set session variable
Thanks Kronin555; it's on a Linux platform but the file name is already all lowercase so I don't think that can be it.... :-\
Jean Genie Guest
-
Kronin555 #7
Re: Cannot set session variable
No, that is _exactly_ it, if your Application.cfm filename is all lowercase.
It _should_ be Application.cfm
that's:
Capital A
p
p
l
i
c
a
t
i
o
n
..
c
f
m
Kronin555 Guest
-
BKBK #8
Re: Cannot set session variable
Hi Jean Genie,
I suspect that, with SessionTimeout="20" , you want sessions to time out
after 20 minutes. However, this setting sets the timeout to an everlasting 20
days!
Another point, that might even be the cause of the problem. We recently
discovered that a little server hangup quickly disappeared when we passed
the timeout value by means of the CreateTimeSpan function. So, use instead
- SessionTimeout="#CreateTimeSpan(20,0,0,0)#" , for 20 days;
- i]SessionTimeout="#CreateTimeSpan(0,0,20,0)#" , for 20 minutes;
BKBK Guest
-
Jean Genie #9
Re: Cannot set session variable
Unfortunately, renaming the file to Application.cfm and changing the timeout
length to 20 min's as suggested is still getting me to "Element USERID is
undefined in SESSION " when I submit my form. Hmph! Does anyone have an
example of what an Application.cfm should look like, and if there is anything
obviously wrong with mine?
Thank you all for your advice, I have already learned lots more than I knew
before. :-)
Jean Genie Guest
-
Kronin555 #10
Re: Cannot set session variable
Jean Genie,
It looks like you're dealing with a pretty deep folder structure.
How many Application.cfm files do you have in your entire site? Do they all
include a root Application.cfm file that has your <cfapplication> tag in it? or
do all that don't include a master Application.cfm file have their own
<cfapplication> tag?
Rather than location.href'ing them away, why not try to output SESSION.UserID
right away, to make sure it's being set correctly.
Kronin555 Guest
-
Jean Genie #11
Re: Cannot set session variable
Kronin555, you saved me. Thank you so much! Most of the site is plain HTML,
and this ColdFusion login stuff is tucked away pretty far down the line as you
noted. I had only one application.cfm file before where the login script was,
so on your suggestion I renamed it "Application.cfm" and copied it into several
folders - and now it works!!! :-)) I'ts probably now in some folders it
doesn't need to be in, but I can delete the unnecessary ones until I figure out
where it needs to be.
Thank you also Jiggar for the cflock advice - looks interesting, I'll look
more into this - and to BKBK for preventing my users from logging in for 20
years! (Just kidding, 20 hours - still needed to be changed.)
You guys rock!
Jean Genie Guest
-
Kronin555 #12
Re: Cannot set session variable
Jean,
You don't need to copy Application.cfm to each folder. The best method is to
have a single Application.cfm file at the root of your web directory.
When a coldfusion page is requested, CF server first looks for an
Application.cfm in that directory. It will continue to look in parent folders
until it either reaches the root of the hard drive or finds an Application.cfm
The only reason to have an Application.cfm in a subfolder is if you have
certain things you need to setup for all the files in that folder and below
(like an Admin-specific Application.cfm, for instance).
Glad you got it working, but I'd get rid of all those extraneous
Application.cfm's and just have one at the web root.
Kronin555 Guest



Reply With Quote

