cflocation problem - not working, instead stays on same page

Discussion in 'Programming' started by lespaul00, Jan 28, 2008.

  1. #1
    Hello,

    I am having problems with cflocation. It works perfectly on my testing server (localhost), but when I upload it to my website, it does not work.

    For example:

    I have the following code at the top of my my_account.cfm page:

    <cfif not isDefined("SESSION.auth.USER_NAME_NAME")>
    <h1>Secure Page</h1>
    <BR />
    <p>You are attempting to access a secure page.</p>
    <p>Please <cfoutput><a href="login.cfm?page=#CGI.SCRIPT_NAME#">login</a></cfoutput> to gain access. If you already have, <A HREF="javascript:history.go(0)">Click here to refresh the page</A>.
    
    Code (markup):
    Then, at the bottom of the login.cfm page I have the following:

    
    <cfoutput>
    <cflocation url="URL.page">
    </cfoutput>
    
    Code (markup):
    Now, I try accessing my_account.cfm without starting a session. Then I click the "login" link on it, which brings me to my login page. I login with a correct username and password, and instead of it sending me back to my_account.cfm (URL.page), it just refreshes the login.cfm page. I DO KNOW that it DOES SUCCESSFULLY start the session, however, the cflocation doesn't seem to be doing the trick. The following shows what is displayed in the URL bar in my browser when it does this:

    http://www.mywebsite.com/my_account.cfm?CFID=12770011&CFTOKEN=38317472
    Code (markup):
    ...even though it still is displaying the login.cfm page.

    Again, it works fine on my testing server. Do you think I need to add in the entire URL (http://www.mywebsite.com/my_account.cfm)?
     
    lespaul00, Jan 28, 2008 IP
  2. lespaul00

    lespaul00 Peon

    Messages:
    283
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Figured it out... javascript workaround:

    <script language="javascript">
    <!--
    document.location.href = "#URL.PAGE#";
    //-->
    </script>
    Code (markup):
    Still don't know why this is a problem though. Basically, I now feel like cflocation is worthless.
     
    lespaul00, Jan 28, 2008 IP
  3. tbarr60

    tbarr60 Notable Member

    Messages:
    3,455
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    210
    #3
    Do you have sessions enabled on the production server?

    Have you output the variables or dumped the scopes to see that you get the variables you expect?

    Don't give up on CFLOCATION it's been around for about 7 versions of CF. Did you try using CFLOCATION without and CFIF conditions?
     
    tbarr60, Jan 28, 2008 IP
  4. lespaul00

    lespaul00 Peon

    Messages:
    283
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Absolutely.


    Yes, I have.


    Hmm, don't know what you mean by this. Mostly, I am using it on a form's action page to direct the user back where they came from. So, I simply put the cflocation tag at the bottom of the page, so it executes last. As I mentioned, it works perfectly on localhost testing, so i'm just confused with it. I think it may have something to do when using #CGI.SCRIPT_NAME# as a passed variable in a URL.
     
    lespaul00, Jan 28, 2008 IP
  5. tbarr60

    tbarr60 Notable Member

    Messages:
    3,455
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    210
    #5
    What I meant was, try putting a CFLOCATION tag in a page by itself and run it on the production server. I am just trying to confirm that CFLOCATION is working on your server and your browser.
     
    tbarr60, Jan 28, 2008 IP
  6. lespaul00

    lespaul00 Peon

    Messages:
    283
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    OK.... this is the deal...


    I created a file called test.cfm:

    
    <cfoutput>
    <cflocation url="index.cfm">
    </cfoutput>
    
    Code (markup):
    When I go to test.cfm, it redirects me to index.cfm as appropriate. However, it does so with the following in the URL:

    ww.mywebsite.com/index.cfmCFID=12770997&CFTOKEN=87501469

    That added portion on the end seems to be my problem. Because, I tried another test as such (more of my type of application):

    test.cfm:

    <cfoutput>
    <cflocation url="test2.cfm?page=index.cfm">
    </cfoutput>
    Code (markup):
    test2.cfm

    <cfoutput>
    <cflocation url="URL.page">
    </cfoutput>
    Code (markup):
    And NOW, when it TRIES to take me to index.cfm, it fails (just displays test2.cfm), and this is shown in the URL:

    ww.mywebsite.com/test2.cfm?page=index.cfm&CFID=12770997&CFTOKEN=87501469

    But it's confusing me because I'd think it SHOULD still work, since the & separates that CFID from the page variable in the URL.

    So, with this new info, any new thoughts?
     
    lespaul00, Jan 29, 2008 IP
  7. tbarr60

    tbarr60 Notable Member

    Messages:
    3,455
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    210
    #7
    Did you try the addToken attribute of cflocation?

    <cflocation url="URL.page" addToken = "No">

    Also you don't need <cfoutput> tags wrapped around the <cflocation> tag. If there is any variable within the cflocation, cfoutput isn;t required.
     
    tbarr60, Jan 29, 2008 IP
  8. lespaul00

    lespaul00 Peon

    Messages:
    283
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Just tried that. Doesn't work. I went from my index.cfm to the login.cfm page carrying the url with cgi.script_name... thus with the following URL:

    http://www.mywebsite.com/login.cfm?page=index.cfm
    Code (markup):
    At the bottom of the login.cfm is the following code:

    <cflocation url="#URL.page#" addToken = "No">
    Code (markup):
    After I log in, the blank login screen is still displayed, and the URL says this:

    http://www.mywebsite.com/index.cfm
    Code (markup):
     
    lespaul00, Jan 30, 2008 IP