ColdFusion Deleting a session variable

12,932

I suspect you mean it's coming back into existence and you think it should be gone. Look for any "cfparams" that set the variable. It might be deleted then reinitiated on the next request.

You can also add a boolean to check if it exists when you delete it.

<cfset exists= structdelete(session, 'username', true)/>  

This will give you a "yes" if it exists and a "no" if it doesn't - allowing you to execute further logic if you wish.

You might also take a look at your application names, session timeout values onsessionStart() etc. I've seen problems where a new session was being instantiated with each request.

Share:
12,932
aelsheikh
Author by

aelsheikh

Updated on June 13, 2022

Comments

  • aelsheikh
    aelsheikh almost 2 years

    I I've done a lot of looking around for code that'll delete a session variable, and the close I've got to success is with this:

    <cfset StructDelete(Session,"username")>
    

    It works the first time, then it never works again. I've spent the past hour on this and am going insane, any help would be much appreciated.

    I'm not sure if this is related but when I modify a .cfm for some reason it doesn't always seem to "update" instantly. What I mean is, I'd change a page, access it and it won't use the new code. This is a horror when trying to debug...