Link to home
Start Free TrialLog in
Avatar of CFbubu
CFbubu

asked on

Cflocation question

Hi,

I am trying to perform a cflocation tag inside of the application.cfc within the onRequestStart function and keep getting an error.

If I leave out the cflocation tag from within the conditional recordcount tag, the pages will open fine. But once I include the cflocation tag, I get an error.

I am trying to run a query on every page to check some details about a User. If the checkuser function comes back with a recordcount greater than 0, i want to direct the user to a specific page no matter where in the site the user was browsing.

I would appreciate it if anyone has a clue why I am getting an error.

Thanks!

Code Sample Below:

<cffunction name="onRequestStart" output="false" returnType="void">

<cfinvoke component="#APPLICATION.somepath#" method="checkUser"  returnvariable="checkUser">
<cfinvokeargument name="User_code" value="#SESSION.User_code#">
</cfinvoke>

         <cfif checkUser.recordcount GT 0>
           
          <cflocation url="../index.cfm" addtoken="no">
                 
            </cfif>


</cffunction>
Avatar of Coast Line
Coast Line
Flag of Canada image

make the methods returntype boolean and it will work

<cffunction name="onRequestStart" returnType="boolean" output="false">
  <cfargument name="thePage" type="string" required="true">

<cfinvoke component="#APPLICATION.somepath#" method="checkUser"  returnvariable="checkUser">
<cfinvokeargument name="User_code" value="#SESSION.User_code#">
</cfinvoke>

         <cfif checkUser.recordcount GT 0>
           
          <cflocation url="../index.cfm" addtoken="no">
                 
            </cfif>  
 <cfreturn true>
</cffunction>
what is your error?
and are you eliminating the code from your index.cfm page (the one that you are locating to)?
SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
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
SOLUTION
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
yup ...

what say you cfbubu?
Avatar of CFbubu
CFbubu

ASKER

Thanks guys! I was indeed causing an infinite loop....oops!

I wanted to build a way to kick logged-in session users. So I was 'flagging' a row in the user database with a value, than using a query in the onrequest in the application.cfc to check on each page load if the user has been flagged by querying that value. If the user has indeed been flagged, than the user will be directed to a specified page. The issue was that I forgot to destroy the user sessions of a 'flagged' user, and thus this ended up creating the infinite loop error.

I also found the tip about  "<cfif NOT cgi.script_name contains "........"> and the small discussion about it  useful..:)

Also, wanted to extend my well wishes to 'gdemaria' and 'dgrafx' - Hi you guys! Not sure if you remember me. It's been a while since I logged in to get help from this site, but I am happy to see that you are all just as active helping us folks out! You guys did help me answer my questions before. Thanks again for the prompt 'teachings' as always! Much appreciated.
Glad it got sorted ...
Have an excellent weekend guys!