Solved

cflocation problem

Posted on 2010-11-22
21
531 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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