Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Coldfusion - redirect to original requested page after login

Posted on 2006-04-05
9
Medium Priority
?
695 Views
Last Modified: 2013-12-24
I have an application.cfm that restricts access to a web app if you are not logged in.  If someone is sent a link to some content in the system, it will redirect them to login before viewing the page .. but after they login, it redirects them to the index page instead of the original request url.  

is it possible to set the requested url in a variable somehow .. so i can pass it back to the redirect after login?   would i set the var in application.cfm?
0
Comment
Question by:grizum
  • 6
  • 3
9 Comments
 
LVL 18

Expert Comment

by:Plucka
ID: 16388917
grizum,

Just put it in a session variable before taking them back to login.

<cfset session.redirect = cgi.script_name />

Then after successsful login

<cfif isDefined("session.redirect")>
    <cflocation url="#session.redirect#" />
</cfif>

Regards
Plucka
0
 

Author Comment

by:grizum
ID: 16389066
im not sure where i should set the variable?

<cfset session.redirect = cgi.script_name />

in the application.cfm?
0
 
LVL 18

Expert Comment

by:Plucka
ID: 16389118
When they return to a book mark, you must already have code that says, hey your not logged in, take to login page.

You need the set in there.

This could be application.cfm, if this is where you send them to login.

If you post your code of application.cfm I could help, you need to be careful about continious loops.
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 

Author Comment

by:grizum
ID: 16389122
yes .. the application.cfm handles that .. here is the code for it.

<cfapplication name="ADMIN" clientmanagement="Yes"
                    sessionmanagement="Yes"
                    sessiontimeout="#CreateTimeSpan(0,4,0,0)#"
                    applicationtimeout="#CreateTimeSpan(1,0,0,0)#">
<cfscript>
    if (NOT structKeyExists(session, 'clickstream')) {
        session.clickstream = arrayNew(1);
    }
</cfscript>

<CFPARAM NAME="session.allow" DEFAULT="false">
<CFPARAM NAME="session.userid" DEFAULT="0">

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

Expert Comment

by:Plucka
ID: 16389217
grizum,

<cfif session.allow neq "true">
    <cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">

    <cfelseif ListLast(CGI.SCRIPT_NAME, "/") EQ "process_login.cfm">

    <cfelse>
        <cfset session.redirect = CGI.SCRIPT_NAME />
        <cflocation url="login.cfm">
    </cfif>
</cfif>

Regards
Plucka
0
 
LVL 18

Expert Comment

by:Plucka
ID: 16389228
Plucka,

Can I pick on your code :) All this, could be done a lot more easily.

<cfif session.allow neq "true">
    <cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">

    <cfelseif ListLast(CGI.SCRIPT_NAME, "/") EQ "process_login.cfm">

    <cfelse>
        <cfset session.redirect = CGI.SCRIPT_NAME />
        <cflocation url="login.cfm">
    </cfif>
</cfif>


LIKE THIS

<cfif session.allow neq "true">
    <cfif Not ListLast(CGI.SCRIPT_NAME, "/") contains "login.cfm">
        <cfset session.redirect = CGI.SCRIPT_NAME />
        <cflocation url="login.cfm">
    </cfif>
</cfif>


OR EVEN THIS

<cfif session.allow neq "true">
    <cfif Not find("login.cfm", CGI.SCRIPT_NAME)>
        <cfset session.redirect = CGI.SCRIPT_NAME />
        <cflocation url="login.cfm">
    </cfif>
</cfif>

Regards
Plucka
0
 
LVL 18

Accepted Solution

by:
Plucka earned 1200 total points
ID: 16389234
Plucka,

OR BETTER STILL

<cfif session.allow neq "true" and Not find("login.cfm", CGI.SCRIPT_NAME)>
    <cfset session.redirect = CGI.SCRIPT_NAME />
    <cflocation url="login.cfm">
</cfif>

Regards
Plucka
0
 

Author Comment

by:grizum
ID: 16391188
awesome man ... thanks!  

i added one thing, thought i would post it here for others and to verify i did it the right way ... i needed it to include the query_string

<cfif session.allow neq "true" and Not find("login.cfm", CGI.SCRIPT_NAME)>
    <cfset session.redirect = CGI.SCRIPT_NAME & "?" & CGI.Query_String />
    <cflocation url="login.cfm">
</cfif>
0
 
LVL 18

Expert Comment

by:Plucka
ID: 16396402
Yep,

That's the way to do it.

Regards
Plucka
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 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