Skip to main content
May 27, 2009
Answered

Logout Syntax Error

  • May 27, 2009
  • 1 reply
  • 5647 views

Hi,

I working on a website with a login and logout set up. I have my login page working fine but I'm having an issue with the logout page. I have it set up so once I log in a "sign off" link appears, taking the user to the logout page. This is my logout.cfm code:

<html>
<head>
<title>Untitled Document</title>
</head>

<body>

        <cfset tmp=StructDelete(session, "username")>
        <cflocation url="/login.cfm?lo" addtoken="no">
       
</body>
</html>

Whenever I run this page, I get this error message;

Variable SESSION is undefined.

Does anyone know what I'm doing wrong?

Thanks in advance for the help.

    This topic has been closed for replies.
    Correct answer Michael Borbor

    No, I'm not using Application.cfc and I doubt its timing out so soon.

    Login.cfm code:

    <!--- Checking the login --->
    <cfif isdefined ("form.username")>
    <cfset good=1>        
        <cfquery name="checklogin" datasource="mydata">
            select username,pw
            from login
            where username='#form.username#' and pw='#form.pw#'
        </cfquery>
    <!--- Set a session and updating visitors count --->
    <cfif checklogin.recordcount is 1 and Compare(form.pw,checklogin.pw) Is 0>
    <cfset session.username='#checklogin.username#'>
    <cfquery name="updatelogin" datasource="mydata">
        update login
        set lastvisit=#now()#, visits = visits + 1
        where username='#session.username#'
    </cfquery>
    <cfelse>
        Incorrect login.
    </cfif>
    </cfif>

    Logout.cfm code:

            <cfset tmp=StructDelete(session, "username")>
            <cflocation url="/login.cfm?lo" addtoken="no">

    Error Message:

    Variable SESSION is undefined.


    There lies your problem:

    http://livedocs.adobe.com/coldfusion/8/sharedVars_11.html

    1 reply

    Michael Borbor
    Inspiring
    May 27, 2009

    How do you create the session variable?

    May 27, 2009

    <cfset session.username='#checklogin.username#'>
            Welcome <cfoutput>#session.username#</cfoutput> | <a href="logout.cfm">Sign Out</a>
            <cfquery name="updatelogin" datasource="mydata">
                update login
                set lastvisit=#now()#, visits = visits + 1
                where username='#session.username#'
            </cfquery>

    Michael Borbor
    Inspiring
    May 27, 2009

    Are you using an Application.cfc? Are you sure your session variables are not being timed out?