Quit and kill the session

I have a login page that works fine. Now I want to log out.

Below is the link in the header.cfm file. If a session variable true, it shows "logout". If not, "login" is displayed. Therefore, I want to do only logout.

<a id="login-link" href="login.cfm">
     <cfif session.userLoggedIn>logout <cfelse>LogIn</cfif>
</a>

Application.cfc

public boolean function onRequestStart(string targetPage)
{

    if(findNocase("login.cfm", arguments.targetPage))
    {
        return true;
    }
    else if(session.userLoggedIn)
        return true;
    else
    {
        include "login.cfm";
        return false;
    }
}

public void function onSessionStart(struct sessionObj)
{

    session.userLoggedIn = false;
}

logIn.cfm

<cfif isDefined("form.btn_login") >
    <cfset userResultResponse =  communtiyServic.getUsers(form.user,form.pwd)>
    <cfset userQry = userResultResponse.getQryData() >

        <cfif userQRY.recordCount gt 0 >
            <cfset session.userLoggedIn = true />
            <cflocation url="index.cfm" >
        <cfelse>
            <cfoutput>invaled userName or password </cfoutput>
    </cfif>



</cfif>
+4
source share
2 answers

CFID CFTOKEN cookie ( , , , ), SessionInvalidate() logout(). . , , , - . , , .

+6

500 , - ... , , url. , OP.

onRequestStart() / location() .

OP / - onRequestStart():

param name="url.logout" default=0; 
if (isDefined('url.logout') and url.logout) {
    if (isDefined('session')){
        /* 
        You can use structDelete(session,'whatever') 
        if you know the session.whatever you are clipping
        and you will have to loop and kill all SO 
        try the structClear() function below.

        */
        structClear(session); 
        /*
        The OP can redirect to login.cfm
        which will auto take them to the login.cfm page
        provided you tack on the ?logout=1 to the URL like this
        http://yoursite.com/somepage.cfm?logout=1
        */
        location(url="login.cfm"); 
    }
}
+3

Source: https://habr.com/ru/post/1546947/


All Articles