Skip to main content
Participant
June 14, 2006
Answered

Login Page

  • June 14, 2006
  • 1 reply
  • 3244 views
Ok, I have a login site that I'm working on. I have the login part working. I'm using session variable to make it work. I have application.cfm, a login.cfm page, a view.cfm page, home.cfm (which holds the main content). Ok, here goes. When someone tries to go to my home.cfm page, if session.loggedin is not set to true, they will get redirected to login.cfm. This is done by code I have in application.cfm. That works fine. But what I'm trying to do is to be able to have a link in my login.cfm page where I can view the contents of view.cfm and be able to go back login.cfm and not allow to see home.cfm without login in. But if I create a link in login.cfm to view.cfm I get looped back to login.cfm because of the code in application.cfm. here is the code in application.cfm:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<!--- Application.cfm --->

<!--- A simple login framework --->

<cfapplication
name="myapp34"
clientmanagement ="yes"
sessionmanagement="yes"
sessiontimeout="#createtimespan(0,0,30,0)#"
>

<!---
By default, a user is not logged in.
--->

<cflock scope="session" type="exclusive" timeout="10">
<cfparam name="session.loggedin" default="False">
</cflock>

<!---

If :
i) the user is not loggedin, AND
NOT on i) login.cfm page,
THEN:
redirect to login.cfm
Endif


The four cases are:


USER Logged in
(Session.loggedin is true)
NOT logged in
On login.cfm page Do nothing Do nothing
NOT on login.cfm page (some other page in the web site) Do nothing Redirect to login.cfm


--->
<cfinclude template="header.cfm">
<cflock scope="session" type="readonly" timeout="10">
<cfif NOT session.loggedin>
<cfif (CGI.script_name is NOT "login.cfm")>
<cflocation URL="login.cfm" addtoken="no">
</cfif>
</cfif>
</cflock>

</body>
</html>
    This topic has been closed for replies.
    Correct answer BKBK
    1) Application.cfm should not have those HTML tags. delete the following:

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    </body>
    </html>

    2) To be able to go into view.cfm, modify the redirecting code logic to, for example,

    If :
    i) the user is not loggedin, AND
    NOT on i) login.cfm page or ii) view.cfm,
    THEN:
    redirect to login.cfm
    Endif

    1 reply

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    June 15, 2006
    1) Application.cfm should not have those HTML tags. delete the following:

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    </body>
    </html>

    2) To be able to go into view.cfm, modify the redirecting code logic to, for example,

    If :
    i) the user is not loggedin, AND
    NOT on i) login.cfm page or ii) view.cfm,
    THEN:
    redirect to login.cfm
    Endif

    Participant
    June 15, 2006
    Thanks! It worked!