Skip to main content
Known Participant
April 23, 2014
Answered

LogOut Issue

  • April 23, 2014
  • 1 reply
  • 36751 views

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" >



This topic has been closed for replies.
Correct answer BKBK

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....


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" />

1 reply

BKBK
Community Expert
April 23, 2014

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.

Known Participant
April 24, 2014

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...

Known Participant
May 1, 2014

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


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)