Solved

cflocation problem

Posted on 2010-11-22
21
529 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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
 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 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