Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

cflocation problem

Posted on 2010-11-22
21
Medium Priority
?
543 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 600 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
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.

 
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 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 1400 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

604 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