Link to home
Start Free TrialLog in
Avatar of RobotMan
RobotManFlag for United States of America

asked on

CFLocation Tag

I am try to use the CFLocation tag to redirect the user to a logon page.  However, when I use the following coed, the browser just runs away and does not come back.

<CFLOCATION url="logon.cfm" addtoken="no">
Avatar of Nathan Stanford Sr
Nathan Stanford Sr
Flag of United States of America image

What do you mean it runs away and does not come back...

We need more information...

1. Is this in the application.cfm file?

If so then you need to make it where when it goes to the logon.cfm files it does a test to see if the file is logon.cfm or not.


2. Is the logon.cfm file in the current directory?
Avatar of agunner
agunner

Hi RobotMan,

Do you mean that it seems to go into an endless loop with your status bar flickering through files?  

Try using a cfinclude:

<cfinclude template="login.cfm">

Hope this helps,

AL
opps..typo

I mean <cfinclude template="logon.cfm>
Sometimes CFLOCATION is a problem becuase the entire page that calls it doesn't load.   Better to use:

<script language="javascript">
   location.replace("logon.cfm");
</script>

:) dapperry
Or , if you want to keep the page in history do something like this:

<body onLoad="document.form1.submit()">
<form name="form1" action="logon.cfm">
</form>
</body>

:) dapperry
Avatar of RobotMan

ASKER

 What I mean by "just runs away" is that the browser turns white, the hour glass "busy" comes on and the browser never shows anything.  And yes, logon.cfm is in the same directory.
  I tried AGunner's suggestion and got the following error:

Template file not found.
HTTP/1.0 404 Object Not Found
The error occurred while processing an element with a general identifier of (CFINCLUDE), occupying document position (1:1) to (1:32).

  If it will help, this is how I am using the code:

<CFAPPLICATION name="SecureApp" clientmanagement="yes" sessionmanagement="yes" setclientcookies="yes">
<CFIF NOT IsDefined("Client.LoggedIn")>
      <CFSET Client.LoggedIn=FALSE>
</CFIF>
<CFIF Client.LoggedIn = FALSE>
        <CFLOCATION url="logon.cfm" addtoken="NO">
</CFIF>
Try what nathans suggested..test inside application.cfm to make sure you're not on the logon.cfm page..if you are, don't execute the code or it will keep looping like you described..

You will probably use the CGI.SCRIPT_NAME variable to get what page you are on.

Give him the points if that works :)
I do not have the code on my logon page...  What do I need to test for???
application.cfm runs at the start of every Cold Fusion page you load.. (if one exists in the same directory or above)

So if logon.cfm and application.cfm are in the same directory, you'll need to do something like this in the application.cfm to skip processing when on the logon page:

<CFAPPLICATION name="SecureApp" clientmanagement="yes" sessionmanagement="yes" setclientcookies="yes">
<CFIF CGI.SCRIPT_NAME DOES NOT CONTAIN "logon.cfm">
<CFIF NOT IsDefined("Client.LoggedIn")>
<CFSET Client.LoggedIn=FALSE>
</CFIF>
<CFIF Client.LoggedIn = FALSE>
        <CFLOCATION url="logon.cfm" addtoken="NO">
</CFIF>
</CFIF>

you might want to use "IS NOT" instead of "DOES NOT CONTAIN"..but check and see exactly what is in CGI.SCRIPT_NAME so that you can do an exact comparison.  (CGI.SCRIPT_NAME is a built in server variable)

Adjusted points from 10 to 15
Okay,  I have inserted the following code into all the pages in my project:

<CFAPPLICATION name="SecureApp" clientmanagement="yes" sessionmanagement="yes" setclientcookies="yes">

<CFIF NOT IsDefined("Client.LoggedIn")>
      <CFSET Client.LoggedIn = FALSE>
</CFIF>
<CFIF Client.LoggedIn EQ FALSE>
      <CFIF CGI.SCRIPT_NAME DOES NOT CONTAIN "logon.cfm">
        <CFLOCATION url="logon.cfm" addtoken="NO">
      </CFIF>
</CFIF>

This seems to be working.  I use the following code on the login page after I have evaluated whether or not the user has supplied the correct information:

<CFSET Client.IDNum = #IDNum#>
<CFSET Client.LoggedIn = TRUE>

I also want to be able to allow the user to log off.  I have attempted doing this by using on onClick event driven button to open a new window with the following code in it:

<CFAPPLICATION name="SecureApp" clientmanagement="yes" sessionmanagement="yes" setclientcookies="yes">

<CFIF NOT IsDefined("Client.LoggedIn")>
      <CFSET Client.LoggedIn = FALSE>
</CFIF>
<CFIF Client.LoggedIn EQ FALSE>
      <CFIF CGI.SCRIPT_NAME DOES NOT CONTAIN "logon.cfm">
        <CFLOCATION url="logon.cfm" addtoken="NO">
      </CFIF>
</CFIF>

<html>
<head><title>Log Off</title></head>
<script LANGUAGE=JAVASCRIPT>
function Refresh()
    {
      opener.location.reload(true);
      window.close();
    }
</script>
<body bgcolor="#003163">

<!-- Here is where I reset the Client variables -->
<CFOUTPUT>
    <CFSET Client.LoggedIn=FALSE>
    <CFSET Clint.IDNum = 0>
</CFOUTPUT>

<center>
<a href="">
<img border="0" src="images/LogOff.gif" onClick="Refresh();">                  
</a>
</center>
</body>
</html>

Yet, this does not seem to work.  In fact, I am having a hard time in general getting the variables to be reset.  Can the values not be set across windows?  If not, then what would you suggest one do to allow a user to log off by pressing a button or closing the window?  Is there a way, as with cookies, that these variables can be set to expire?  Can I use javascript to reassign the variables, or does the work need to be done server side?
I tried out your code and it seems to work fine (after one correction..see below)  The code to reset the variables is correct.

It is a little interesting how you are using the javascript, but i see what it does..the code actually logs them off before the image is clicked, however.

Let me know a little more about what it's doing wrong if you can..

Some comments:

1) Client is misspelled in the logoff page above..I had to correct that to get it work.  Did you overlook that perhaps?

2) The code for checking to see if they've logged in or not can and should eventually be kept in the application.cfm page so that you don't have to put it on every page.  application.cfm runs automatically before every page if it exists in the same directory or above.
ASKER CERTIFIED SOLUTION
Avatar of Dain_Anderson
Dain_Anderson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial