Answered
Login Page
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>
<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>