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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I use 2 CFIF statements to send users to different locations? 1

Status
Not open for further replies.

SteelDragon

Programmer
Feb 1, 2001
134
US
Ok, I have a problem that is two fold.
1) I have 2 CFIF statements (see below) and I want to use them to send a person to a location based on their membership in a group. So far CF picks up the first CFIF, but not the second. It immediatly goes to the CFElse if the first CFIF is not true. How can i do this where if one CFIF is not true, it goes to the second CFIF, and THEN goes to the Else if none of the conditions are met.

2) I have setup security on this site, and I want the session variables to allow a user to move from one page to another, I have it setup now so when the user logs in they are sent to a specific URL, how can I make this look at the requested URL, and then log them in and send them there instead of hard coding it? I have put example code for each below:


1)
<cftry>

<cfif CheckUser.WebCustomer is -1>
<cflocation url=&quot;../Scripts/cgi-bin/cgirdir.exe?PartnerFTP&quot; addtoken=&quot;no&quot;>

<cfif CheckUser.WebPartner is -1>
<cflocation url=&quot;../Scripts/cgi-bin/cgirdir.exe?CustomerFTP&quot; addtoken=&quot;no&quot;>

<cfelse>
<cflocation url=&quot; addtoken=&quot;no&quot;>
</CFIF></cfif>

2)
<CFIF SESSION.LOGGEDIN>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
self.location ='support_search.cfm';
</SCRIPT>
<CFELSE>
<CFOUTPUT>
<SCRIPT>
alert(&quot;Your login was unsuccessful because #Reason# Please try your login again.&quot;);
self.location=&quot;login.cfm&quot;;
</SCRIPT>
</CFOUTPUT>
 
Hey Steel,

I think you want your second <cfif> to be a <cfelseif> statement which should work the way you want.

On the other, I always set a session variable to hold the current url before re-directing to a login page. On the login page, I then re-direct back based on the session variable that holds their original location. You can get the current script name from cgi.script_name and also append any url variables with cgi.querystring.

Hope this helps,
GJ
 
GJ, I understand What you are saying, I just don't know How to do it. I'm only a Converted MS Certified NT Guy, who had CF knowledge and was thrown to the wolves so to speak.... So I have been learining on the Go. I really appreciate all of the help you and many others have given me. Words cannot express my gratitude. I put the CFElseIf in... and now my page does not forward at all. As to the other part.... I'm lost. Here is my application.cfm:

<CFAPPLICATION NAME=&quot;MyApplication&quot; SESSIONMANAGEMENT=&quot;Yes&quot; SESSIONTIMEOUT=&quot;#CreateTimeSpan(0,0,0,30)#&quot; APPLICATIONTIMEOUT=&quot;#CreateTimeSpan(0,0,0,30 )#&quot;>

<CFPARAM NAME=&quot;session.LoggedIn&quot; DEFAULT=&quot;FALSE&quot;>

<CFSET APPTIMESPAN = #CREATETIMESPAN(0,0,0,30)#>

<CFIF #SESSION.LOGGEDIN# IS &quot;FALSE&quot;>

<CFIF (CGI.SCRIPT_NAME IS NOT &quot;/PowerOLAP/login.cfm&quot;) AND (CGI.SCRIPT_NAME IS NOT &quot;/PowerOLAP/results.cfm&quot;)>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>alert(&quot;The system has detected you have not logged in or your session on this machine has timed out. You will now be prompted for your login/password.&quot;);self.location='login.cfm';
</SCRIPT>
</CFIF>
<CFELSE>
<CFIF (CGI.SCRIPT_NAME IS NOT &quot;/PowerOLAP/login.cfm&quot;) AND (CGI.SCRIPT_NAME IS NOT &quot;/PowerOLAP/results.cfm&quot;)>

<CFSET APPLICATION.USERSLOGGEDIN[&quot;#Session.UserID#&quot;].TIMECREATED = NOW()>
</CFIF>

</CFIF>

------------AND HERE IS THE ACTION PAGE FOR THIS:----------

<CFSET SESSION.LOGGEDIN = FALSE>

<CFQUERY NAME=&quot;CheckUser&quot; DATASOURCE=&quot;support&quot; username=&quot;search&quot;>
SELECT WebUserID, WebPassword, WebPartner, WebCustomer
FROM Person
WHERE WebUserID = '#Form.WebUserID#' and WebUSER = '-1'
</CFQUERY>


<CFIF CHECKUSER.RECORDCOUNT GREATER THAN 0>

<CFIF CHECKUSER.WebPASSWORD IS FORM.WebPASSWORD>

<CFIF #ISDEFINED(&quot;application.UsersLoggedin&quot;)# IS FALSE>
<CFSET APPLICATION.USERSLOGGEDIN=STRUCTNEW()>
</CFIF>

<CFSET USERIDATDOOR = CHECKUSER.WebUSERID>

<CFIF #STRUCTKEYEXISTS(APPLICATION.USERSLOGGEDIN, USERIDATDOOR)# IS TRUE>

<CFSET ENDTIME = #APPLICATION.USERSLOGGEDIN[USERIDATDOOR].TIMECREATED# + #APPTIMESPAN#>

<CFIF #DATECOMPARE(&quot;#Now()#&quot;, &quot;#EndTime#&quot;)# IS 1>

<CFOUTPUT>
<CFSCRIPT>
StructDelete(application.UsersLoggedin,#CheckUser.WebUserID#, true);
</CFSCRIPT>
</CFOUTPUT>

<CFSET SESSION.LOGGEDIN = TRUE>

<CFSET SESSION.USERID = CHECKUSER.WebUSERID>

<CFSET APPLICATION.USERSLOGGEDIN[&quot;#session.UserID#&quot;] = SESSION>

<CFSET APPLICATION.USERSLOGGEDIN &quot;#Session.UserID#&quot;].TIMECREATED = NOW()>

<CFELSE>
<CFOUTPUT>

<CFIF #DATEDIFF(&quot;n&quot;, &quot;#Now()#&quot;, &quot;#EndTime#&quot;)# LT 1>

<CFSET MINUTESLEFT = 'LESS THAN ONE'>
<CFELSE>

<CFSET MINUTESLEFT = #DATEDIFF(&quot;n&quot;, &quot;#Now()#&quot;, &quot;#EndTime#&quot;)#>
</CFIF>
<CFSET REASON = &quot;: \n\n1- User #CheckUser.WebUserID# is already logged in;OR\n2- You have terminated your last session abnormally (e.g., your computer crashed).\n\nThis account will be unlocked #MinutesLeft# minute(s) from now.&quot;>

</CFOUTPUT>

</CFIF>

<CFELSE>

<CFSET SESSION.LOGGEDIN = TRUE>

<CFSET SESSION.USERID = CHECKUSER.WebUSERID>

<CFSET APPLICATION.USERSLOGGEDIN[&quot;#session.UserID#&quot;] = SESSION>

<CFSET APPLICATION.USERSLOGGEDIN[&quot;#Session.UserID#&quot;].TIMECREATED = NOW()>

</CFIF>
<CFELSE>
<CFSET REASON = &quot;the Password you typed in is invalid. Please try again&quot;>
</CFIF>
<CFELSE>
<CFOUTPUT>
<CFSET REASON = 'the User Name #FORM.WebUSERID# could not be located.'>
</CFOUTPUT>
</CFIF>
<CFIF SESSION.LOGGEDIN>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
self.location ='CGI.Script_Name';
</SCRIPT>
<CFELSE>
<CFOUTPUT>
<SCRIPT>alert(&quot;Sorry! Your login was unsuccessful because #Reason#&quot;);self.location=&quot;login.cfm&quot;;
</SCRIPT>
</CFOUTPUT>
<cfinclude template=&quot;FTP.cfm&quot;>
</CFIF>
----------- Here is my last page, the redirector--------

<CFAPPLICATION NAME=&quot;MyApplication&quot; SESSIONMANAGEMENT=&quot;Yes&quot; SESSIONTIMEOUT=&quot;#CreateTimeSpan(0,0,0,30)#&quot; APPLICATIONTIMEOUT=&quot;#CreateTimeSpan(0,0,0,30 )#&quot;>
<CFPARAM NAME=&quot;session.LoggedIn&quot; DEFAULT=&quot;FALSE&quot;>

<CFIF #SESSION.LOGGEDIN# IS &quot;FALSE&quot;>

<CFIF (CGI.SCRIPT_NAME IS NOT &quot;/PowerOLAP/login.cfm&quot;) AND (CGI.SCRIPT_NAME IS NOT &quot;/PowerOLAP/results.cfm&quot;)>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>alert(&quot;The system has detected you have not logged in or your session on this machine has timed out. You will now be prompted for your login/password.&quot;);self.location='login.cfm';
</SCRIPT>
</CFIF>
<CFELSE>

<CFIF (CGI.SCRIPT_NAME IS NOT &quot;/PowerOLAP/login.cfm&quot;) AND (CGI.SCRIPT_NAME IS NOT &quot;/PowerOLAP/results.cfm&quot;)>

<CFSET APPLICATION.USERSLOGGEDIN[&quot;#Session.UserID#&quot;].TIMECREATED = NOW()>
</CFIF>
</CFIF>
<cftry>
<cfif CheckUser.WebCustomer is -1>

<cflocation url=&quot;../Scripts/cgi-bin/cgirdir.exe?PartnerFTP&quot; addtoken=&quot;no&quot;>

<cfif CheckUser.WebPartner is -1>
<cflocation url=&quot;../Scripts/cgi-bin/cgirdir.exe?CustomerFTP&quot; addtoken=&quot;no&quot;>

<cfelse>
<cflocation url=&quot; addtoken=&quot;no&quot;>
</cfif></cfif>
<cfcatch>
</cfcatch>
</cftry>
 
Hey Steel,

I'm happy to help and I'll explain in more detail as you need. If it were me, I would put the login files in a separate directory with an application.cfm file that doesn't have the login check in it. I would then use the <cflocation> to re-direct instead of JS as it's more reliable. This is how I would then re-structure what you have:

<CFIF #SESSION.LOGGEDIN# IS &quot;FALSE&quot;>
<cflocation url=&quot;/PowerOLAP/login.cfm&quot;>
<CFELSE>
<CFSET APPLICATION.USERSLOGGEDIN[&quot;#Session.UserID#&quot;].TIMECREATED= NOW()>
</CFIF>

I think that using the same application.cfm file for the login page can bite you later if any name changes as you are looking for a specific url that has to be updated anytime a path or script name changes.

Let me know if this helps,
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top