Solved

cflocation problem

Posted on 2010-11-22
21
519 Views
Last Modified: 2012-05-10
Hello experts
I want to use cflocation in my application.cfm to redirect not logged in users to the login.cfm page
but i get a browser error that the page is not redirecting right and that the load process has stopped(free translation).
the code:
<cfif session.allowin neq "true">
<cflocation url="login.cfm">
</cfif>

Using the next code it is working:
<cfif session.allowin neq "true">
      <cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">
      <cfelse>
      <!--- this user is not logged in, alert user and redirect to the login.cfm page --->
      <script>
           
              self.location="login.cfm";
      </script>
      </cfif>
</cfif>

I want to use the first code.
Any helpto fix it?
0
Comment
Question by:Panos
  • 11
  • 7
  • 3
21 Comments
 
LVL 19

Assisted Solution

by:Bhavesh Shah
Bhavesh Shah earned 150 total points
ID: 34186367
Hi,

you must be tried it still, did u check this.

<cfif session.allowin neq "true">
      <cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">
      <cfelse>
     <cflocation url="login.cfm">
      </cfif>
</cfif>
0
 
LVL 2

Author Comment

by:Panos
ID: 34186516
Hi Brichsoft.
Sometimes the solution is in front of me and i don't see it.
The redirecting problem has been solved and a new one did come up.
I have a captcha image (<img src="#request.AdminPath#captcha/captchaImage.cfm?r=<cfoutput>#gettickcount()#</cfoutput>" id="sessioncaptcha" alt="captcha" width="190" height="60">)
on the login page that is not loading any more.
0
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 34186542
hi,

can u share us the code??
0
 
LVL 2

Author Comment

by:Panos
ID: 34186572
Check this:
<!--- application part --->
<cfscript>
SetEncoding("form","utf-8");
SetEncoding("url","utf-8");
</cfscript>
<cfsetting enablecfoutputonly="true">
<cfcontent type="text/html; charset=utf-8">
<cfset application.vlangid = 3 >
<cfset this.secureJSON = "false">
<cfset request.AdminPath = 'http://mydomain/admin/'>
<cfset request.homeURL = "http://mydomain/">
<cfset request.dsn = "carbay">
<CFPARAM NAME="session.user_id"  type="numeric" DEFAULT="0">

<!--- Now define that this user is logged out by default --->
<CFPARAM NAME="session.allowin" DEFAULT="false">

<CFPARAM NAME="session.clientlocked"  type="numeric" DEFAULT="0">

<cfapplication clientmanagement="Yes"
               sessiontimeout="#CreateTimeSpan(0,0,30,0)#"
               applicationtimeout="#CreateTimeSpan(0,2,0,0)#"
               sessionmanagement="yes"
               setclientcookies="yes"/>
               
<cfif session.allowin neq "true">
      <cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">
      <cfelse>
     <cflocation url="login.cfm">
      </cfif>
</cfif>



<!--- login part --->
<div style="float:left; display:inline; text-align:left; width:194px;">Reload Captcha
  <span style="display:inline-block"><img src="#request.AdminPath#admincaptcha/captchaImage.cfm?r=<cfoutput>#gettickcount()#</cfoutput>" id="sessioncaptcha" alt="captcha" width="190" height="60"></span><button type="button" name="btnRefreshCaptcha" class="login_button" value="#getLang.Text#" onClick="document.getElementById('sessioncaptcha').src='#request.AdminPath#admincaptcha/captchaImage.cfm?r='+new Date().getTime();"/>Reload Captcha</button></div>
 
 
<!--- captchaImage.cfm --->
<cfscript>
function getRandomCaptchaText(){
  var rStr = "";
        var i = 0;
  rStr = rStr & Chr(RandRange(Asc("A"),Asc("Z")));
  rStr = rStr & Chr(RandRange(Asc("A"),Asc("Z")));
  for(i=0;i<3;i=i+1){
    rStr = rStr & Chr(RandRange(Asc("0"),Asc("9")));
  };
  return rStr;
}
</cfscript>
<cfset Session.captcha_adminText = getRandomCaptchaText()/>
<cfset captchaimagepath = getdirectoryfrompath(getcurrenttemplatepath()) & 'admincaptcha' & gettickcount() & '.png'>
<cfimage action="captcha" width="192" height="60" text="#session.captcha_adminText#" destination="#captchaimagepath#" difficulty="medium">
<cfcontent reset="yes" type="image/png" file="#captchaimagepath#" deletefile="yes">
0
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 34186604
Hi,

Try this

<cfoutput>

<img src="#request.AdminPath#captcha/captchaImage.cfm?r=#gettickcount()#" id="sessioncaptcha" alt="captcha" width="190" height="60">

</cfoutput>
0
 
LVL 2

Author Comment

by:Panos
ID: 34186633
The problem remains.
0
 
LVL 2

Author Comment

by:Panos
ID: 34186656
i set one output in the login page to check the session output:
#Session.captcha_adminText#
When i click on the button to change the session value and than reload the page nothing happens.
This means that something is wrong with the path setting when i use cflocation.
Checking the source code everything is OK.
0
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 34186685
Hi,

Show your code closely.

<img src="#request.AdminPath#admincaptcha/captchaImage.cfm?r=<cfoutput>#gettickcount()#</cfoutput>" id="sessioncaptcha" alt="captcha" width="190" height="60">

I dont think,this can be done.

you doing first time???

I think you need to use ajax....to show image
0
 
LVL 2

Author Comment

by:Panos
ID: 34186687
This code in application has the same result:
<cfif session.allowin neq "true">
<cfinclude template="login.cfm">
<cfabort>
</cfif>
0
 
LVL 2

Author Comment

by:Panos
ID: 34186696
It is the first time i use the code in the admin/application.cfm page because i want to protect the admin folder.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 2

Author Comment

by:Panos
ID: 34186702
Can you suggest another tutorial using ajax with the possibility to change tha captcha text?
0
 
LVL 2

Author Comment

by:Panos
ID: 34186711
0
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 34186769
Hi,

If its already given by expert and worked once then you no need to change it.
we will find the problem and then solved....anyways I'm sure once agx show this Question,you will surely get answer soon ;-)

anyways finally where we stuck....can u say again???PLS
0
 
LVL 2

Author Comment

by:Panos
ID: 34186805
The code is working(captcha image is showing and the button is changing the session value) only if i use the javascript way  in application.cfm
<cfif session.allowin neq "true">
      <cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">
      <cfelse>
      <!--- this user is not logged in, alert user and redirect to the login.cfm page --->
      <script>
           
              self.location="login.cfm";
      </script>
      </cfif>
</cfif>

Not the cflocation either the cfinclude.
0
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 34187050
Hi,

I understud the problem....and i know this happens with cflocation but not able to say exact reason.....

I will get back to you soon....
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 350 total points
ID: 34202807
<cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">

Open in new window


Oh dear... If captchaImage.cfm is in the same directory as your Application.cfm, that won't work.  captchaImage.cfm is a CF page too ;-) so every time the login page gets a new image, CF will run the Application.cfm ... again.

It will see the user is NOT logged in:
           <cfif session.allowin neq "true">
   
... the page requested ("captchaImage.cfm") is NOT "login.cfm"

      <cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">

... so it will redirect to Login.cfm (or possibly create an infinite loop).

          <cflocation url="login.cfm">

Either way, the captcha image never loads!  To fix it, either exclude the captchaImage.cfm page too, or move it outside the Application.cfm directory.

ie
<cfif session.allowin neq "true">
    <cfif NOT ListFindNoCase("login.cfm,captchaImage.cfm", ListLast(CGI.SCRIPT_NAME, "/"))>
	    <cflocation url="login.cfm" addtoken="false">
    </cfif>
</cfif>

Open in new window


Totally unrelated ...

<cfset this.secureJSON = "false">

Open in new window


The "this" scope only applies to Application.cfc files, not .cfm.  Also the session variable cfparam's should come after the cfapplication tag.  So you might want review the code. Tighten it up, and maybe switch to an Application.cfc too.

0
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 34202821

Agx sir,

You late by one day. ;-)

I was expecting your reply yesterday........
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34202896
lol.  I didn't notice the thread was stalled until today ;-)
0
 
LVL 2

Author Comment

by:Panos
ID: 34204740
!!!!WOW THATS IT !!!
Thank you very much agx for the solution and for the advices to my application.cfm page.


(like Brichsoft allready said:You late by one day)

0
 
LVL 2

Author Closing Comment

by:Panos
ID: 34204748
thank you again.
Some points are given to expert Brichsoft for his interest.
regards
panos
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34207141
>> You late by one day

lol.  Well we've all got jobs outside of EE ;-)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

21 Experts available now in Live!

Get 1:1 Help Now