Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect Back To Same Page 1

Status
Not open for further replies.

coldfused

Technical User
Joined
Jan 27, 2001
Messages
2,442
Location
US
Guys I have a login script that if login fails redirects back to:

<cfset LoginFailed="index.cfm?loginfailed=yes">

Now I use this login script on every single page almost, but would rather they redirect back to the page they were on with "loginfailed=yes" rather than back to the index page.

How would I make them redirect back to whatever page they were on and pass the loginfailed variable in the url?

Thanks,
Carl

----------------------------------------
Florida Web Design
Orlando Web Hosting
Florida Coldfusion Hosting
 
Neither way works r937. Am I missin something? How does cgi.path_info know which page its on, or am i supposed to pass something else along with that? Tried both ways above and it just gets caught up on the login script page and stops there.

Here's the code:
Code:
<cfif IsDefined("FORM.Username")>
  <cfset LoginSuccess="member.cfm">
  <cfset LoginFailed="index.cfm?loginfailed=yes">
  <cfquery  name="getMember">
  SELECT * FROM Members WHERE Username='#FORM.Username#' AND Password='#FORM.Password#'
  </cfquery>
  <cfif getMember.RecordCount NEQ 0>
	  <cfset Session.Auth.Member=#getMember.Member#>
      <cflocation url="#LoginSuccess#" addtoken="no">
  <cfelse>
  <cflocation url="#LoginFailed#" addtoken="no">
  </cfif>
</cfif>

Sorry if Im missing something,
Carl

----------------------------------------
Florida Web Design
Orlando Web Hosting
Florida Coldfusion Hosting
 
I understand the path was not right I changed it back when I pasted the code to show you what I had.

What do you mean my outer cfif statement does not have an cfelse? Should it?

It works fine redirecting back to the index page with the on cfelse I have, which is all I can see I need, am I missing something?

----------------------------------------
Florida Web Design
Orlando Web Hosting
Florida Coldfusion Hosting
 
Would it be this? If so it still sticks on the login script and goes no where.

Code:
<cfif IsDefined("FORM.Username")>
  <cfset LoginSuccess="member.cfm">
  <cfset LoginFailed="#cgi.path_info#?loginfailed=yes">
  <cfquery  name="getMember">
  SELECT * FROM Members WHERE Username='#FORM.Username#' AND Password='#FORM.Password#'
  </cfquery>
  <cfif getMember.RecordCount NEQ 0>
	  <cfset Session.Auth.Member=#getMember.Member#>
      <cflocation url="#LoginSuccess#" addtoken="no">
  <cflocation url="#LoginFailed#" addtoken="no">
  </cfif>
<cfelse>
<cflocation url="#cgi.path_info#?loginfailed=yes" addtoken="no">
</cfif>

----------------------------------------
Florida Web Design
Orlando Web Hosting
Florida Coldfusion Hosting
 
The form thats resides on each page is processed by a script on lets say login.cfm which only has the code:
Code:
<cfif IsDefined("FORM.Username")>
  
  <cfset LoginSuccess="member.cfm">
  <cfset LoginFailed="#cgi.script_name#?loginfailed=yes">
  
  <cfquery  name="getMember">
  SELECT * FROM Members WHERE Username='#FORM.Username#' AND Password='#FORM.Password#'
  </cfquery>
  
  <cfif getMember.RecordCount NEQ 0>
	  <cfset Session.Auth.Member=#getMember.Member#>
      <cflocation url="#LoginSuccess#" addtoken="no">
  <cfelse>
  <cflocation url="#LoginFailed#" addtoken="no">
  </cfif>

<cfelse>
<cflocation url="#cgi.script_name#?loginfailed=yes" addtoken="no">

</cfif>

If I enter the correct username and password the script validates and passes to the member page. Now with the cgi.script_name is does not pass if login fails it just hangs on the login script and never passes as "loginfailed" back to the users current page with the error message provided if the page redirects back and sets the variable "loginfailed".

----------------------------------------
Florida Web Design
Orlando Web Hosting
Florida Coldfusion Hosting
 
This method will not work cause I have the script on another page to do the processing, the cg.script_name or cgi.path_info is being processed on the script page so it gets stuck there.

If I move the login member script to the page itself and do the checking there it will work correct?

----------------------------------------
Florida Web Design
Orlando Web Hosting
Florida Coldfusion Hosting
 
okay, i think i know why i was so confused

i didn't understand that you only do the login script on the single login.cfm page

you said "Now I use this login script on every single page"

so what's actually going on is that every page submits the form to login.cfm, and login.cfm is supposed to send them back to where they came from

(i personally wouldn't do it that way, but hey, let's not get more confused than we already are)

so instead of cgi.path_info, use cgi.referer

:-)



rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (next course starts March 6 2005)
 
Yes thank you...

Sorry for the confusion, great help as usual. And im sure im probably confusing as hell to you but hey, thats why im the newbie and your helping me with your knowledge.

Thanks again,
Carl

----------------------------------------
Florida Web Design
Orlando Web Hosting
Florida Coldfusion Hosting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top