1 2 Previous Next 46 Replies Latest reply on Jul 16, 2014 7:04 AM by BKBK

    LogOut Issue

    Shraddha Prajapati

      Hi

          When i logout from my index Page then Login Page Open but when i click on back button in Browser Then  Index Page open. I want once logout then not open other when clik on back button in Browser page like facebook..

      I add my code Follow:

       

      Application.cfc

      <cfcomponent>

                <cfset this.datasource = "TestingDataSource">

       

                <cffunction name="onRequest">

                          <cfargument name="templatename"/>

                          <cflogin>

                                    <cfif isdefined("form.submit")>

                                              <cfif form.username is "admin" and form.password is "admin">

                                                        <cfloginuser name="#form.username#" password="#form.password#" roles="admin">

                                              <cfelse>

                                                        <cfset request.errorMessage = "Incorrect Login,Please try again..">

                                                        <cfinclude template="login.cfm">

                                                        <cfreturn>

                                              </cfif>

                                    <cfelse>

                                              <cfinclude template="login.cfm">

                                              <cfreturn>

                                    </cfif>

                          </cflogin>

                          <cfinclude template="#arguments.templatename#" >

                </cffunction>

       

      </cfcomponent>


       

      index.cfm

      <!DOCTYPE html>

      <html>

                <head>

                          <meta http-equiv="Content-Type" content="text/html"; charset="utf-8"/>

                          <title>

                                    Untitled Document

                          </title>

                </head>

                <body>

                          <h1>Home Page</h1>

                          <h3>

                                    Welcome to Photo Gallary.....

                          </h3>

                          <a href="logout.cfm">Logout</a>

                </body>

      </html>

       

      login.cfm

      <!DOCTYPE html>

      <html>

                <head>

                          <meta

                          

                          http-equiv="Content-Type" content="text/html"; charset="utf-8"/>

                          <title>

                                    Untitled Document

                          </title>

                </head>

                <body>

                          <cfform>

                                    <table width="500" border="0">

                                              <tr>

                                                        <td>

                                                                  User Name:

                                                        </td>

                                                        <td>

                                                                  <cfinput name="username" type="text" required="yes" message="Please enter Username"/>

                                                        </td>

                                              </tr>

                                              <tr>

                                                        <td>

                                                                  Password:

                                                        </td>

                                                        <td>

                                                                  <cfinput name="password" type="password" required="yes" message="Please enter password"/>

                                                        </td>

                                              </tr>

                                              <tr>

                                                        <td>

                                                                  <cfinput type="submit" name="submit" value="submit">

                                                        </td>

                                              </tr>

                                    </table>

                          </cfform>

                          <cfif isdefined("request.errorMessage")>

                                    <p style="color:red">

                                              <cfoutput>#request.errorMessage#</cfoutput>

                                    </p>

                          </cfif>

                </body>

      </html>

       

      logout.cfm

      <cflogout>

      <cflocation url="login.cfm" >



        • 1. Re: LogOut Issue
          BKBK Adobe Community Professional & MVP

          Just 2 things. 1) The login code in onRequest would probably be better placed in onRequestStart. 2) The behaviour you observe is as expected. As a result of the cflocation, the browser thinks the visitor of login.cfm came from index.cfm. Anyway, it is generally considered bad practice to prevent the user from using the browser's back-button to go back. However, if you insist, google disable browser back button and you will find useful Javascript suggestions.

          • 2. Re: LogOut Issue
            Shraddha Prajapati Level 1

            Only google disable browser back button i can do this ya any other way to solve it? like by using session...In starting assisgn value in session and after logout destroy session like this ,if you have demo then please give me code...

            • 3. Re: LogOut Issue
              BKBK Adobe Community Professional & MVP

              It is futile to try to control the bowser's back-button from the server. Controlling the behaviour of the browser is, in general, a matter for the browser, not for the ColdFusion server.

               

              Button behaviour and navigation are among the decisions that the browser can make independently of the server. One notable example is that the browser may decide to serve a cached version of a page, rather than make a new trip to the server. So any booby-traps or cunning decoys you set for it would just be for nothing. That is why most developers implement such functionalities in Javascript.

              • 4. Re: LogOut Issue
                Shraddha Prajapati Level 1

                Hi

                    I dont want to apply disable browser back button...Have you  any other way to solve it?

                • 5. Re: LogOut Issue
                  BKBK Adobe Community Professional & MVP

                  As far as I can see, there is not much use in using the browser to prevent a logged out user from going back to index.cfm. This is all about authentication, so I think it is a server issue anyway. I can think of one consistent piece of server logic for that.

                   

                  It makes sense to display the logout link only if the user is logged in. You could therefore test for this.

                   

                  You could also check whether the user is already logged in, in deciding whether or not to display the login page. Both tests can be done by means of getAuthUser().

                   

                  If the user has logged out or is not yet logged in, then getAuthUser() will be an empty string. For a user currently logged in, getAuthUser() returns the value of the name attribute of the cfloginuser tag.

                   

                  Putting it all together, you should get something like:

                   

                  <cffunction name="onRequestStart">

                                       <cfargument name = "targetPage" type="String" required="true">

                                      <cflogin>

                                                <cfif isdefined("form.submit")>

                                                          <cfif form.username is "admin" and form.password is "admin">

                                                                    <cfloginuser name="#form.username#" password="#form.password#" roles="admin">

                                                          <cfelse>

                                                                    <cfset request.errorMessage = "Incorrect Login,Please try again..">

                                                                    <cfinclude template="login.cfm">

                                                                   <cfabort>

                                                          </cfif>

                                                <cfelseif getAuthUser() is "">

                                                          <cfinclude template="login.cfm">

                                                         <cfabort>

                                                </cfif>

                                      </cflogin>

                            </cffunction>

                   

                   

                  index.cfm

                  <!DOCTYPE html>

                  <html>

                  etc., etc

                    <cfif NOT (getAuthUser() is "")>

                          <a href="logout.cfm">Logout</a>

                  </cfif>

                  </body>

                  </html>

                  • 6. Re: LogOut Issue
                    Shraddha Prajapati Level 1

                    Hi, 

                        I add code in my app according you above say for (check whether the user is already logged in, in deciding whether or not to display the login page.).But its not solve my above issue,

                    • 7. Re: LogOut Issue
                      BKBK Adobe Community Professional & MVP

                      Shraddha Prajapati wrote:

                       

                      Hi, 

                          I add code in my app according you above say for (check whether the user is already logged in, in deciding whether or not to display the login page.).But its not solve my above issue,

                      The code is not meant to solve the issue of going from login.cfm to index.cfm using the back-button. It is meant to make the issue irrelevant.

                      • 8. Re: LogOut Issue
                        BKBK Adobe Community Professional & MVP

                        BKBK wrote:

                         

                        index.cfm

                        <!DOCTYPE html>

                        <html>

                        etc., etc

                          <cfif NOT (getAuthUser() is "")>

                                <a href="logout.cfm">Logout</a>

                        </cfif>

                        </body>

                        </html>

                         

                        Even better:

                         

                        index.cfm

                        <!DOCTYPE html>

                        <html>

                        etc., etc

                        <cfif getAuthUser() is "">

                                <a href="login.cfm">Login</a>

                        </cfelse>

                                <a href="logout.cfm">Logout</a>

                        </cfif>

                        </body>

                        </html>

                        • 9. Re: LogOut Issue
                          Shraddha Prajapati Level 1

                          Its not work.... I want once logout then not open other Page(Prev  Page) , open Login Page ,when clik on back button in Browser ,   like facebook..

                          • 10. Re: LogOut Issue
                            BKBK Adobe Community Professional & MVP

                            We are now back to where we started. If you must, you should do it in Javascript.

                             

                            If you insist on doing it at the server, start by telling the browser not to cache index.cfm (the page you don't want to be opened by back button).

                             

                            index.cfm

                             

                            <html>

                            <head>

                            <!--- Tell browser not to cache this page, and to make fresh request of page each time --->

                            <meta http-equiv="cache-control" content="no-cache">

                            <meta http-equiv="expires" content="Mon, 22 jul 2002 11:12:01 GMT"><!---Time in the past--->

                            </head>

                             

                            Suppose a user requests index.cfm. If his last requested page is login.cfm, you want ColdFusion to send him back to the login page. Implement that logic in onRequestStart.

                             

                            <cffunction name="onRequestStart">

                                <cfargument name = "targetPage" type="String" required="true">

                                <cfset current_page = listLast(arguments.targetPage, "/")>

                                <cfif current_page is "index.cfm" and (isDefined("session.pageLastVisited") and session.pageLastVisited is "login.cfm")>

                                    <cflocation url="login.cfm">

                                </cfif>

                                <cfset session.pageLastVisited = current_page>

                            </cffunction>

                            • 11. Re: LogOut Issue
                              Shraddha Prajapati Level 1

                              I got the error:

                               

                              The web site you are accessing has experienced an unexpected error.
                              Please contact the website administrator.


                              The following information is meant for the website developer for debugging purposes.
                              Error Occurred While Processing Request

                              The requested scope session has not been enabled.

                              Before session variables can be used, the session state management system must be enabled using the cfapplication tag.
                              The error occurred in C:/ColdFusion10/cfusion/wwwroot/demo/demo1/Login3/Application.cfc: line 26

                                25 :<cfset current_page = listLast(arguments.targetPage, "/")>

                              26 :    <cfif current_page is "index.cfm" and (isDefined("session.pageLastVisited") and session.pageLastVisited is "login.cfm")>

                              27 :    <cflocation url="login.cfm"> 28 :          </cfif>


                              • 12. Re: LogOut Issue
                                BKBK Adobe Community Professional & MVP

                                What you have to do is clear. Start the Application.cfc file with something like

                                 

                                <cfcomponent>

                                <cfset this.name = "Shraddha1">

                                <cfset this.datasource = "TestingDataSource">

                                <cfset this.applicationTimeout = "#createTimespan(1,0,0,0)#">

                                <cfset this.sessionManagement = "true">

                                <cfset this.sessionTimeout = "#createTimeSpan(0,0,20,0)#">

                                <cfset this.loginStorage = "session">

                                • 13. Re: LogOut Issue
                                  BKBK Adobe Community Professional & MVP

                                  Please confirm what suggestions you have used before asking further questions. It would help the forum give you even better suggestions.

                                  • 14. Re: LogOut Issue
                                    Shraddha Prajapati Level 1

                                    Forget this...I am very confused in this...And also its no work....

                                    Plz Give me the code of your  demo of login Example, With Applicatio.cfc,login.cfm,index.cfm,logout.cfm Page..(Simple Demo with session and  check whether the user is already logged in, in deciding whether or not to display the login page and solve with browser back button)

                                    • 15. Re: LogOut Issue
                                      BKBK Adobe Community Professional & MVP

                                      The tips I have given you so far should work. It of course depends on how you implemented them. Could you show us your files: Application.cfc, login.cfm, index.cfm, and logout.cfm.

                                      • 16. Re: LogOut Issue
                                        Shraddha Prajapati Level 1

                                        Ok I give you my another login  example code:

                                         

                                        Application.cfc

                                        component {

                                                  this.name="logindemo";

                                                  this.sessionManagement="true";

                                                  this.sessionTimeOut = createTimeSpan(0,0,0,15);

                                                  public boolean function onRequestStart(string req)

                                                  {

                                                            var append = "";

                                                            var togo = "";

                                         

                                                            //handle an authentication

                                                            if(structKeyExists(form, "login") && structKeyExists(form, "username") && structKeyExists(form, "password")) {

                                                                      if(form.username == "admin" && form.password == "password") {

                                                                                session.loggedin = true;

                                         

                                                                                if(structKeyExists(session, "requestedurl")) {

                                                                                          togo = session.requestedurl;

                                                                                          structDelete(session, "requestedurl");

                                                                                          location(url=togo, addtoken=false);

                                                                                }

                                                                      } else {

                                                                                append = "?error=1";

                                                                      }

                                                            }

                                         

                                                            //force login if not authenticated

                                                            if(!session.loggedin && !find("login.cfm", arguments.req)) {

                                                                      session.requestedurl = arguments.req & "?" & cgi.query_string;

                                                                      if(!structIsEmpty(form)  && !structKeyExists(form, "login")) session.formdata = serializeJSON(form);

                                                                      location(url='login.cfm#append#',addtoken=false);

                                                            }

                                         

                                         

                                                            //Got Form?

                                                            if(session.loggedin && structKeyExists(session, "formData") and isJSON(session.formData)) {

                                                                      structAppend(form,deserializeJSON(session.formData));

                                                                      structDelete(session, "formData");

                                                            }

                                                            return true;

                                                  }

                                                  public void function onSessionStart() {

                                                            session.loggedin=false;

                                         

                                                  }

                                        }

                                         

                                        login.cfm

                                        <h2>Please Login</h2>

                                        <p>Use admin and password for your username and password.</p>

                                        <cfif structKeyExists(url, "error")>

                                                  <p>You didn't enter the right credentials!</p>

                                        </cfif>

                                        <form action="index.cfm" method="post">

                                        username: <input type="text" name="username"><br/>

                                        password: <input type="password" name="password"><br/>

                                        <input type="submit" name="login" value="Login">

                                        </form>

                                        index.cfm

                                        <!DOCTYPE html>

                                        <html>

                                                  <head>

                                                            <meta http-equiv="Content-Type" content="text/html"; charset="utf-8"/>

                                                            <!---<meta http-equiv="cache-control" content="no-cache">

                                                            <meta http-equiv="expires" content="Mon, 22 jul 2002 11:12:01 GMT"><!---Time in the past--->--->

                                                            <title>

                                                                      Untitled Document

                                                            </title>

                                                  </head>

                                                  <body>

                                                            <h1>Home Page</h1>

                                                            <h3>

                                                                      Welcome to Photo Gallary.....

                                                            </h3>

                                                            <a href="logout.cfm">Logout</a>

                                         

                                                  </body>

                                        </html>

                                         

                                        logout.cfm

                                        <cfset session.loggedin = "false">

                                        <cflogout>

                                        <cflocation url="login.cfm">

                                         

                                         

                                        In this Example only one problem ,Browser back button issue....I dont want to disable it(Browser back button)..I want to find other way to solve it ....Once logout and click on Browser back button, then open only login page.....


                                        • 17. Re: LogOut Issue
                                          BKBK Adobe Community Professional & MVP

                                          Shraddha Prajapati wrote:

                                           

                                          Ok I give you my another login  example code:

                                           

                                          You have changed to yet another example. This is what I advised you in a previous post to avoid. If you continue to add new parts to the code before correcting the existing code, you will generate a lot of complexity. That will make debugging difficult.

                                          • 18. Re: LogOut Issue
                                            BKBK Adobe Community Professional & MVP

                                            You have not implemented the following suggestions I gave you:

                                             

                                            1) define the application variables in Application.cfc (For example, I suggested a session timeout of 20 minutes. Your current value of 15 seconds is unrealistic.);

                                             

                                            2) use meta tags in index.cfm to prevent caching;

                                             

                                            3) use the variable session.pageLastVisited in onRequestStart to prevent the user going back to index.cfm.

                                            • 19. Re: LogOut Issue
                                              Shraddha Prajapati Level 1

                                              hi , I apply your above 3 suggestions in my new Demo:

                                               

                                              index.cfm

                                              <!DOCTYPE html>

                                              <html>

                                                <head>

                                                <meta http-equiv="Content-Type" content="text/html"; charset="utf-8"/>

                                                <!--- Tell browser not to cache this page, and to make fresh request of page each time --->

                                                <meta http-equiv="cache-control" content="no-cache">

                                                <meta http-equiv="expires" content="Mon, 22 jul 2002 11:12:01 GMT"><!---Time in the past--->

                                                <title>

                                                Untitled Document

                                                </title>

                                                </head>

                                                <body>

                                                <h1>Home Page</h1>

                                                <h3>

                                                Welcome to Photo Gallary.....

                                                </h3>

                                                <a href="logout.cfm">Logout</a>

                                               

                                                </body>

                                              </html>

                                               

                                              Application.cfc

                                              component {

                                                this.name="logindemo";

                                                this.datasource = "TestingDataSource";

                                                this.applicationTimeout = "#createTimespan(1,0,0,0)#";

                                                this.sessionManagement="true";

                                                this.sessionTimeOut = createTimeSpan(0,0,0,15);

                                                this.loginStorage = "session";

                                                public boolean function onRequestStart(string req)

                                                {

                                                var append = "";

                                                var togo = "";

                                                var targetPage="";

                                                current_page = listLast(targetPage, "/");

                                                if(current_page is "index.cfm" & (isDefined("session.pageLastVisited") and session.pageLastVisited is "login.cfm"))

                                                {

                                                location(url="login.cfm");

                                                }

                                                session.pageLastVisited = current_page;

                                                //handle an authentication

                                                if(structKeyExists(form, "login") && structKeyExists(form, "username") && structKeyExists(form, "password")) {

                                                if(form.username == "admin" && form.password == "password") {

                                                session.loggedin = true;

                                               

                                                if(structKeyExists(session, "requestedurl")) {

                                                togo = session.requestedurl;

                                                structDelete(session, "requestedurl");

                                                location(url=togo, addtoken=false);

                                                }

                                                } else {

                                                append = "?error=1";

                                                }

                                                }

                                               

                                                //force login if not authenticated

                                                if(!session.loggedin && !find("login.cfm", arguments.req)) {

                                                session.requestedurl = arguments.req & "?" & cgi.query_string;

                                                if(!structIsEmpty(form)  && !structKeyExists(form, "login")) session.formdata = serializeJSON(form);

                                                location(url='login.cfm#append#',addtoken=false);

                                                }

                                               

                                               

                                                //Got Form?

                                                if(session.loggedin && structKeyExists(session, "formData") and isJSON(session.formData)) {

                                                structAppend(form,deserializeJSON(session.formData));

                                                structDelete(session, "formData");

                                                }

                                                return true;

                                                }

                                                public void function onSessionStart() {

                                                session.loggedin=false;

                                               

                                                }

                                              }

                                              • 20. Re: LogOut Issue
                                                Shraddha Prajapati Level 1

                                                But its not work....

                                                • 21. Re: LogOut Issue
                                                  BKBK Adobe Community Professional & MVP

                                                  Shraddha Prajapati wrote:

                                                   

                                                  this.sessionTimeOut = createTimeSpan(0,0,0,15);

                                                  As I said earlier, 15 seconds is impractical. Use 20 minutes, for example.

                                                   

                                                  public boolean function onRequestStart(string req)

                                                    {

                                                    var append = "";

                                                    var togo = "";

                                                    var targetPage="";

                                                    current_page = listLast(targetPage, "/");

                                                  That is inconsistent with the code I gave you, and will of course fail because targetPage is an empty string. The correct code is

                                                   

                                                  public boolean function onRequestStart(string targetPage)

                                                    {

                                                     var current_page = listLast(arguments.targetPage, "/");

                                                  • 22. Re: LogOut Issue
                                                    Shraddha Prajapati Level 1

                                                    Ok.I cange my code above you say...

                                                    this.sessionTimeOut = createTimeSpan(0,0,0,20);


                                                    public boolean function onRequestStart(string targetPage)

                                                    {

                                                       var current_page = listLast(arguments.targetPage, "/");

                                                     

                                                    But its not work......

                                                    • 23. Re: LogOut Issue
                                                      BKBK Adobe Community Professional & MVP

                                                      Shraddha Prajapati wrote:

                                                       

                                                      Ok.I cange my code above you say...

                                                      this.sessionTimeOut = createTimeSpan(0,0,0,20);

                                                      That is 20 seconds. Twenty minutes is createTimeSpan(0,0,20,0).

                                                       


                                                      But its not work......

                                                      Why does it fail? What are the error messages? Could you please give us some details.

                                                      • 24. Re: LogOut Issue
                                                        BKBK Adobe Community Professional & MVP

                                                        Shraddha Prajapati wrote:

                                                         

                                                        if(current_page is "index.cfm" & (isDefined("session.pageLastVisited") and session.pageLastVisited is "login.cfm"))

                                                        if(structKeyExists(form, "login") && structKeyExists(form, "username") && structKeyExists(form, "password"))

                                                        if(form.username == "admin" && form.password == "password")

                                                        if(!session.loggedin && !find("login.cfm", arguments.req))

                                                        if(!structIsEmpty(form)  && !structKeyExists(form, "login"))

                                                        if(session.loggedin && structKeyExists(session, "formData") and isJSON(session.formData))

                                                        ...

                                                        But its not work......

                                                        Stay with traditional Coldfusion syntax, and you should be all right.

                                                         

                                                        if(current_page is "index.cfm" AND (isDefined("session.pageLastVisited") and session.pageLastVisited is "login.cfm"))

                                                        if(structKeyExists(form, "login") AND structKeyExists(form, "username") AND structKeyExists(form, "password"))

                                                        if(form.username EQ "admin" AND form.password EQ "password")

                                                        if(NOT session.loggedin AND NOT find("login.cfm", arguments.req))

                                                        if(NOT structIsEmpty(form)  AND NOT structKeyExists(form, "login"))

                                                        if(session.loggedin AND structKeyExists(session, "formData") and isJSON(session.formData))

                                                        • 25. Re: LogOut Issue
                                                          Shraddha Prajapati Level 1

                                                          Done it above you say.....

                                                          this.sessionTimeOut = createTimeSpan(0,0,20,0);

                                                          if(current_page is "index.cfm" AND (isDefined("session.pageLastVisited") and session.pageLastVisited is "login.cfm"))

                                                          if(structKeyExists(form, "login") AND structKeyExists(form, "username") AND structKeyExists(form, "password"))

                                                          if(form.username EQ "admin" AND form.password EQ "password")

                                                          if(NOT session.loggedin AND NOT find("login.cfm", arguments.req))

                                                          if(NOT structIsEmpty(form)  AND NOT structKeyExists(form, "login"))

                                                          if(session.loggedin AND structKeyExists(session, "formData") and isJSON(session.formData))

                                                           

                                                          Still not work it.....

                                                          Not Work means when logout and click back button then the previous page(index.cfm) will open.....

                                                          Now????

                                                          • 26. Re: LogOut Issue
                                                            BKBK Adobe Community Professional & MVP

                                                            Try these 3 meta tags for preventing caching. View the page source to confirm the meta tags are arriving at the browser.

                                                             

                                                            index.cfm


                                                            <!DOCTYPE html>

                                                            <html>

                                                              <head>

                                                              <meta http-equiv="Content-Type" content="text/html"; charset="utf-8"/>

                                                              <!--- Tell browser not to cache this page, and to make fresh request of page each time --->

                                                            <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">

                                                            <meta http-equiv="Pragma" content="no-cache">

                                                            <meta http-equiv="Expires" content="0">

                                                              <title>

                                                              Untitled Document

                                                              </title>

                                                              </head>

                                                              <body>

                                                              <h1>Home Page</h1>

                                                              <h3>

                                                              Welcome to Photo Gallary.....

                                                              </h3>

                                                              <a href="logout.cfm">Logout</a>

                                                             

                                                              </body>

                                                            </html>

                                                            • 27. Re: LogOut Issue
                                                              BKBK Adobe Community Professional & MVP

                                                              Please show us the current code of login.cfm and logout.cfm.

                                                              • 28. Re: LogOut Issue
                                                                Shraddha Prajapati Level 1

                                                                login.cfm

                                                                <h2>Please Login</h2>

                                                                <p>Use admin and password for your username and password.</p>

                                                                <cfif structKeyExists(url, "error")>

                                                                  <p>You didn't enter the right credentials!</p>

                                                                </cfif>

                                                                <form action="index.cfm" method="post">

                                                                username: <input type="text" name="username"><br/>

                                                                password: <input type="password" name="password"><br/>

                                                                <input type="submit" name="login" value="Login">

                                                                </form>

                                                                 

                                                                logout.cfm

                                                                <cfset session.loggedin = "false">

                                                                <cflogout>

                                                                <cflocation url="login.cfm">

                                                                • 29. Re: LogOut Issue
                                                                  BKBK Adobe Community Professional & MVP

                                                                  Thanks. Expect me back in a moment.

                                                                  • 30. Re: LogOut Issue
                                                                    BKBK Adobe Community Professional & MVP

                                                                    Shraddha,

                                                                    Strip the code down to its bare essentials, and you will find that the suggestion I gave you works. For example, put the following 4 files in the same directory. Then open index.cfm in the browser, and click on the 'Logout' link. You will arrive at login.cfm. Clicking on the browser's back button will not take you back to index.cfm.

                                                                     

                                                                    Application.cfc

                                                                    component {

                                                                      this.name="logindemo";

                                                                      this.applicationTimeout = createTimespan(1,0,0,0);

                                                                      this.sessionManagement="true";

                                                                      this.sessionTimeOut = createTimeSpan(0,0,20,0);

                                                                      this.loginStorage = "session";

                                                                      public boolean function onRequestStart(string targetPage)

                                                                      {

                                                                          var current_page = listLast(arguments.targetPage, "/");

                                                                          if(current_page is "index.cfm" AND (isDefined("session.pageLastVisited") AND session.pageLastVisited is "login.cfm"))

                                                                          {

                                                                              location(url="login.cfm");

                                                                          }

                                                                              session.pageLastVisited = current_page;

                                                                              return true;

                                                                      }

                                                                    }

                                                                     

                                                                    index.cfm

                                                                    <!DOCTYPE html>

                                                                    <html>

                                                                      <head>

                                                                      <meta http-equiv="Content-Type" content="text/html"; charset="utf-8"/>

                                                                      <!--- Tell browser not to cache this page, and to make fresh request of page each time --->

                                                                      <meta http-equiv="cache-control" content="no-cache">

                                                                      <meta http-equiv="expires" content="Mon, 22 jul 2002 11:12:01 GMT"><!---Time in the past--->

                                                                      <title>

                                                                      Untitled Document

                                                                      </title>

                                                                      </head>

                                                                      <body>

                                                                      <h1>Home Page</h1>

                                                                      <h3>

                                                                      Welcome to Photo Gallary.....

                                                                      </h3>

                                                                      <a href="logout.cfm">Logout</a>

                                                                      </body>

                                                                    </html>

                                                                     

                                                                    login.cfm

                                                                    <h2>Please Login</h2>

                                                                    <p>Use admin and password for your username and password.</p>

                                                                    <cfif structKeyExists(url, "error")>

                                                                      <p>You didn't enter the right credentials!</p>

                                                                    </cfif>

                                                                    <form action="index.cfm" method="post">

                                                                    username: <input type="text" name="username"><br/>

                                                                    password: <input type="password" name="password"><br/>

                                                                    <input type="submit" name="login" value="Login">

                                                                    </form>

                                                                     

                                                                    logout.cfm

                                                                    <cfset session.loggedin = "false">

                                                                    <cflogout>

                                                                    <cflocation url="login.cfm">

                                                                    • 31. Re: LogOut Issue
                                                                      Shraddha Prajapati Level 1

                                                                      No its not work....When i open index.cfm in the browser, and click on the 'Logout' link. i will arrive at login.cfm. Clicking on the browser's back button will take me back to index.cfm...You can try it....

                                                                      • 32. Re: LogOut Issue
                                                                        BKBK Adobe Community Professional & MVP

                                                                        I had tried it beforehand. It worked.

                                                                         

                                                                        Nevertheless, following your comment, I tested the solution on 3 browsers. I can confirm what you found. By coincidence, it works on my default browser, Internet Explorer, but fails on Chrome and Firefox.

                                                                         

                                                                        What about the following alternative? I have designed it such that, during testing, you have to wait only 10 seconds for the login to time out. (In normal use, set idletimeout to the value of sessiontimeout, that is, 1200 seconds, or set no value at all)

                                                                         

                                                                        Application.cfc

                                                                        component {

                                                                          this.name="logindemo";

                                                                          this.applicationTimeout = createTimespan(1,0,0,0);

                                                                          this.sessionManagement="true";

                                                                          this.sessionTimeOut = createTimeSpan(0,0,20,0);

                                                                          this.loginStorage = "session";

                                                                         

                                                                          public boolean function onRequestStart(string targetPage)

                                                                          {

                                                                              var current_page = listLast(arguments.targetPage, "/");

                                                                             if(current_page is "index.cfm" AND getAuthUser() is "")   // User not yet logged in

                                                                             {

                                                                                if (NOT IsDefined("form.login")) // No login form submitted

                                                                                {

                                                                                    cfinclude (template="login.cfm"); abort;

                                                                                }

                                                                                else {

                                                                                    // Put authentication validation code here

                                                                                    cflogin (idletimeout="10") // To enable quick testing, set timeout temporarily at low value of 10 seconds

                                                                                    {

                                                                                        cfloginuser (name = "#form.username#", password = "#form.password#", roles = "admin");

                                                                                    }

                                                                                }

                                                                             }

                                                                             return true;

                                                                          }

                                                                        }

                                                                        • 33. Re: LogOut Issue
                                                                          Shraddha Prajapati Level 1

                                                                          Its still not work i got error:

                                                                          Variable CFLOGIN is undefined.

                                                                          The error occurred in C:/ColdFusion10/cfusion/wwwroot/demo/Login/TestLogin/Application.cfc: line 41

                                                                           

                                                                          41 : if(cflogin (idletimeout="10")) // To enable quick testing, set timeout temporarily at low value of 10 seconds

                                                                          42 : {

                                                                          43 : cfloginuser (name = "#cflogin.name#", password = "#cflogin.password#", roles = "admin");

                                                                          • 34. Re: LogOut Issue
                                                                            Shraddha Prajapati Level 1

                                                                            Variable CFLOGINUSER is undefined.

                                                                            The error occurred in C:/ColdFusion10/cfusion/wwwroot/demo/Login/TestLogin/Application.cfc: line 43

                                                                            43 : cfloginuser (name = "#cflogin.name#", password = "#cflogin.password#", roles = "admin");

                                                                            • 35. Re: LogOut Issue
                                                                              BKBK Adobe Community Professional & MVP

                                                                              Sorry. That was in ColdFusion 11. Here is a more suitable syntax:

                                                                               

                                                                              <cfcomponent>

                                                                                <cfset this.name="logindemo">

                                                                                <cfset this.applicationTimeout = createTimespan(1,0,0,0)>

                                                                                <cfset this.sessionManagement="true">

                                                                                <cfset this.sessionTimeOut = createTimeSpan(0,0,20,0)>

                                                                                <cfset this.loginStorage = "session">

                                                                               

                                                                                   <cffunction name="onRequestStart">

                                                                                  <cfargument name = "targetPage" type="String" required="true">

                                                                               

                                                                                  <cfset var current_page = listLast(arguments.targetPage, "/")>

                                                                               

                                                                                   <cfif current_page is "index.cfm" AND getAuthUser() is ""> <!--- User not yet logged in --->

                                                                                      <cfif NOT IsDefined("form.login")> <!--- No login form submitted --->

                                                                                          <cfinclude template="login.cfm">

                                                                                          <cfabort>

                                                                                      <cfelse>

                                                                                          <!--- Put authentication validation code here --->

                                                                                          <cflogin idletimeout="10"> <!--- To enable quick testing, set timeout low at 10 seconds --->

                                                                                              <cfloginuser name = "#form.username#" password = "#form.password#" roles = "admin">

                                                                                          </cflogin>

                                                                                      </cfif>

                                                                                   </cfif>

                                                                               

                                                                                   <cfreturn true>

                                                                                   </cffunction>

                                                                              </cfcomponent>

                                                                              • 36. Re: LogOut Issue
                                                                                Shraddha Prajapati Level 1

                                                                                Still its not work....When i login and open index.cfm in the browser, and click on the 'Logout' link. i will arrive at login.cfm. Clicking on the browser's back button will take me back to index.cfm...You can try it....

                                                                                • 37. Re: LogOut Issue
                                                                                  BKBK Adobe Community Professional & MVP

                                                                                  I have tested the latest code I gave you on Internet Explorer 11, Firefox 29 and Chrome. It works. When I press the back button, it does not take me back to index.cfm.

                                                                                   

                                                                                  To test, use the latest version of Application.cfc (posted May 6, 2014 4:53 PM ). Use the following, new set of meta tags in index.cfm to prevent caching.

                                                                                   

                                                                                  <meta http-equiv="cache-control" content="max-age=0" />

                                                                                  <meta http-equiv="cache-control" content="no-cache" />

                                                                                  <meta http-equiv="expires" content="0" />

                                                                                  <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />

                                                                                  <meta http-equiv="pragma" content="no-cache" />

                                                                                  • 38. Re: LogOut Issue
                                                                                    Shraddha Prajapati Level 1

                                                                                    Thanks for your reply...

                                                                                              I add this meta tag in index.cfm

                                                                                     

                                                                                    <meta http-equiv="cache-control" content="max-age=0" />

                                                                                    <meta http-equiv="cache-control" content="no-cache" />

                                                                                    <meta http-equiv="expires" content="0" />

                                                                                    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />

                                                                                    <meta http-equiv="pragma" content="no-cache" />

                                                                                     

                                                                                    You say use latest version of Application.cfc (posted May 6, 2014 4:53 PM ) ,But Application.cfc (posted May 6, 2014 4:53 PM ) its not exist.....

                                                                                    You mean you tell about Application.cfc(May 6, 2014 7:53 AM) , then i already use it....

                                                                                     

                                                                                    But still not works......

                                                                                    Please Show me your code file.....(index.cfm,Application.cfc,login.cfm,logout.cfm)

                                                                                    • 39. Re: LogOut Issue
                                                                                      BKBK Adobe Community Professional & MVP

                                                                                      The forum site apparently takes account of time-zone, hence the difference in time. Anyway, put the following 4 files in the same directory, and test with them.

                                                                                       

                                                                                      I have tested with these files on the latest versions of Internet Explorer, Firefox and Chrome. The code works as expected, in every case. After logout, the user cannot go back to index.cfm by means of the back button.

                                                                                       

                                                                                      Application.cfc

                                                                                      <cfcomponent>

                                                                                        <cfset this.name="logindemo">

                                                                                        <cfset this.applicationTimeout = createTimespan(1,0,0,0)>

                                                                                        <cfset this.sessionManagement="true">

                                                                                        <cfset this.sessionTimeOut = createTimeSpan(0,0,20,0)>

                                                                                        <cfset this.loginStorage = "session">

                                                                                       

                                                                                           <cffunction name="onRequestStart">

                                                                                          <cfargument name = "targetPage" type="String" required="true">

                                                                                       

                                                                                          <cfset var current_page = listLast(arguments.targetPage, "/")>

                                                                                       

                                                                                           <cfif current_page is "index.cfm" AND getAuthUser() is ""> <!--- User not yet logged in --->

                                                                                              <cfif NOT IsDefined("form.login")> <!--- No login form submitted --->

                                                                                                  <cfinclude template="login.cfm">

                                                                                                  <cfabort>

                                                                                              <cfelse>

                                                                                                  <!--- Put authentication validation code here --->

                                                                                                  <cflogin idletimeout="10"> <!--- To enable quick testing, set timeout low at 10 seconds --->

                                                                                                      <cfloginuser name = "#form.username#" password = "#form.password#" roles = "admin">

                                                                                                  </cflogin>

                                                                                              </cfif>

                                                                                           </cfif>

                                                                                       

                                                                                           <cfreturn true>

                                                                                           </cffunction>

                                                                                      </cfcomponent>

                                                                                       

                                                                                      index.cfm

                                                                                      <!DOCTYPE html>

                                                                                      <html>

                                                                                        <head>

                                                                                        <meta http-equiv="Content-Type" content="text/html"; charset="utf-8"/>

                                                                                        <!--- Tell browser not to cache this page, and to make fresh request of page each time --->

                                                                                      <!--- First version --->

                                                                                      <!---  <meta http-equiv="cache-control" content="no-cache">

                                                                                        <meta http-equiv="expires" content="Mon, 22 jul 2002 11:12:01 GMT"> ---><!---Time in the past--->

                                                                                      <!--- Second version --->

                                                                                      <!--- <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">

                                                                                      <meta http-equiv="Pragma" content="no-cache" />

                                                                                      <meta http-equiv="Expires" content="Mon, 22 jul 2002 11:12:01 GMT"> --->

                                                                                      <!--- Third version --->

                                                                                      <meta http-equiv="cache-control" content="max-age=0" />

                                                                                      <meta http-equiv="cache-control" content="no-cache" />

                                                                                      <meta http-equiv="expires" content="0" />

                                                                                      <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />

                                                                                      <meta http-equiv="pragma" content="no-cache" />

                                                                                        <title>

                                                                                        Untitled Document

                                                                                        </title>

                                                                                        </head>

                                                                                        <body>

                                                                                        <h1>Home Page</h1>

                                                                                        <h3>

                                                                                        Welcome to Photo Gallary.....

                                                                                        </h3>

                                                                                      <cfif NOT (getAuthUser() is "")>

                                                                                      <p>User logged in: <cfoutput>#getAuthUser()#</cfoutput></p>

                                                                                      </cfif>

                                                                                       

                                                                                      <a href="logout.cfm">Logout</a>

                                                                                       

                                                                                        </body>

                                                                                      </html>

                                                                                       

                                                                                      login.cfm

                                                                                      <h2>Please Login</h2>

                                                                                      <p>Use admin and password for your username and password.</p>

                                                                                      <cfif structKeyExists(url, "error")>

                                                                                        <p>You didn't enter the right credentials!</p>

                                                                                      </cfif>

                                                                                      <form action="index.cfm" method="post">

                                                                                      username: <input type="text" name="username"><br/>

                                                                                      password: <input type="password" name="password"><br/>

                                                                                      <input type="submit" name="login" value="Login">

                                                                                      </form>

                                                                                       

                                                                                      logout.cfm

                                                                                      <cflogout>

                                                                                      <cflocation url="login.cfm">

                                                                                      1 2 Previous Next