Solved

Cflocation question

Posted on 2012-03-15
8
700 Views
Last Modified: 2012-03-16
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>
0
Comment
Question by:CFbubu
8 Comments
 
LVL 15

Expert Comment

by:myselfrandhawa
Comment Utility
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>
0
 
LVL 24

Expert Comment

by:dgrafx
Comment Utility
what is your error?
and are you eliminating the code from your index.cfm page (the one that you are locating to)?
0
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 333 total points
Comment Utility
dgrafx is making a great point, if I understand it correctly, he is suggesting that you could end up in an infinite loop here.

what you get to index.cfm page, the same checkUser query will again return 0 records (because nothing has changed) and you will again be redirected to index.cfm page (even though you're already there).

You need to add a check to make sure you don't get redirected to the page you're already on.

<cfif NOT cgi.script_name contains "/index">
    .... now checkUser ...

</cfif>
0
 
LVL 24

Accepted Solution

by:
dgrafx earned 167 total points
Comment Utility
yes - thats what i meant - thank you ...

and since your target page is named index.cfm and all your directories probably have an index.cfm - you need to either specify exactly like if cgi.script_name is not "/index.cfm"
which means the index.cfm file that is in the root directory but will not match an index.cfm file that is in a folder named xyz as it would be "/xyz/index.cfm".
OR you can rename your "special" page - such as "loginspecial.cfm".
your code would then be if NOT cgi.script_name containsnocase "loginspecial.cfm"
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 333 total points
Comment Utility
yes, good point.   "contains" is not the best solution there.  I like the idea of using a new file name best.   Even if that file name simply includes the index page (assuming that's the home page perhaps)

loginRequired.cfm ...
   <cfset accessDenied = true>
   <cfinclude template="index.cfm">


Then inside of index.cfm you can test for "accessDenied" and show special messages.  This is one way to reuse the home page but with different messages displayed and also control the redirect from within your application.cfc file..
0
 
LVL 24

Expert Comment

by:dgrafx
Comment Utility
yup ...

what say you cfbubu?
0
 

Author Closing Comment

by:CFbubu
Comment Utility
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.
0
 
LVL 24

Expert Comment

by:dgrafx
Comment Utility
Glad it got sorted ...
Have an excellent weekend guys!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now