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

This is what has to be done. If

Status
Not open for further replies.

GUJUm0deL

Programmer
Jan 16, 2001
3,676
US
This is what has to be done. If the user is comming to the site from an outside url, then they get an alert message and then are redirected.
The problem is that for some reason this seems to loop. The alert keeps popping up again and again. This code seems to work if the url in window.location.href is one directory up. Why?
For instance:
I have it like this now: window.location.href = "page.cfm" and it seems to loop like this (the alert keeps popping up again and again)
If I put the page.html in an directory above, like this: window.location.href = "../page.cfm" it works fine.
Why?? Any ideas??


The code we're using:
Code:
<CFAPPLICATION NAME=&quot;MyApplication&quot; SESSIONMANAGEMENT=&quot;Yes&quot; SESSIONTIMEOUT=&quot;#CreateTimeSpan(0,0,45,0)# APPLICATIONTIMEOUT=#CreateTimeSpan(0,0,45,0)#&quot;>

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

<!-- If the user is not logged in, not currently on the login page, 4gotten the password -->
<CFIF #session.LoggedIn IS &quot;FALSE&quot;>
  <CFIF (CGI.SCRIPT_NAME IS NOT &quot;file.cfm&quot;)
    AND (CGI.SCRIPT_NAME IS NOT &quot;file_name.cfm&quot;)
	AND (CGI.SCRIPT_NAME IS NOT &quot;file_name2.cfm&quot;)
	
	<script>
      alert(&quot;you are being redirected&quot;);
      window.location.href = &quot;login.cfm&quot;;
	</script>
	</CFIF></CFIF>
I have not failed; I merely found 100,000 different ways of not succeding...
 
Because you are saying.. &quot;Redirect if it is not this page&quot;.. well the page you redirect to is not those pages either so it will do it until it gets on the correct page and of course it won't because of your CFIF statement.. for isntance...

change:
<CFIF #session.LoggedIn IS &quot;FALSE&quot;>
<CFIF (CGI.SCRIPT_NAME IS NOT &quot;file.cfm&quot;)
AND (CGI.SCRIPT_NAME IS NOT &quot;file_name.cfm&quot;)
AND (CGI.SCRIPT_NAME IS NOT &quot;file_name2.cfm&quot;)

<script>
alert(&quot;you are being redirected&quot;);
window.location.href = &quot;login.cfm&quot;;
</script>
</CFIF></CFIF>

to:
<CFIF #session.LoggedIn IS &quot;FALSE&quot;>
<CFIF (CGI.SCRIPT_NAME IS NOT &quot;file.cfm&quot;
AND (CGI.SCRIPT_NAME IS NOT &quot;file_name.cfm&quot;
AND (CGI.SCRIPT_NAME IS NOT &quot;file_name2.cfm&quot;
AND (CGI.SCRIPT_NAME IS NOT &quot;file_name2.cfm&quot;
AND (CGI.SCRIPT_NAME IS NOT &quot;login.cfm&quot;)>

<script>
alert(&quot;you are being redirected&quot;);
window.location.href = &quot;login.cfm&quot;;
</script>
</CFIF></CFIF>

Thanks,
Tony Hicks
AIM: Webmigit
Yahoo: Webmigit
MSN: Webmigit@hotmail.com
 
oops.

change:
<CFIF #session.LoggedIn IS &quot;FALSE&quot;>
<CFIF (CGI.SCRIPT_NAME IS NOT &quot;file.cfm&quot;)
AND (CGI.SCRIPT_NAME IS NOT &quot;file_name.cfm&quot;)
AND (CGI.SCRIPT_NAME IS NOT &quot;file_name2.cfm&quot;)

<script>
alert(&quot;you are being redirected&quot;);
window.location.href = &quot;login.cfm&quot;;
</script>
</CFIF></CFIF>

to:
<CFIF #session.LoggedIn IS &quot;FALSE&quot;>
<CFIF (CGI.SCRIPT_NAME IS NOT &quot;file.cfm&quot;
AND CGI.SCRIPT_NAME IS NOT &quot;file_name.cfm&quot;
AND CGI.SCRIPT_NAME IS NOT &quot;file_name2.cfm&quot;
AND CGI.SCRIPT_NAME IS NOT &quot;file_name2.cfm&quot;
AND CGI.SCRIPT_NAME IS NOT &quot;login.cfm&quot;)>

<script>
alert(&quot;you are being redirected&quot;);
window.location.href = &quot;login.cfm&quot;;
</script>
</CFIF></CFIF>

Thanks,
Tony Hicks
AIM: Webmigit
Yahoo: Webmigit
MSN: Webmigit@hotmail.com
 
Tony,
Usually the cgi.script_name may have a leading &quot;/&quot; in front of the name -- try doing a simple <cfoutput>#cgi.script_name#</cfoutput> in the application.cfm to ensure you have the entire name correct. If it is in the root directory, it could be
&quot;/file.cfm&quot;
&quot;/file_name.cfm&quot;

etc.

Tim P.
 
Thanks for responding, OK Tony I actualy made a mistake when I posted my original question...we do have login.cfm in the <CFIF> statements...in all my haste I forgot to add that...
But the problem still remains, I actualy changed the oder of the <script> and something wierd happens...if I place the alert() message first then the window.location.href the alert will go through a loop continusly, but if I place the window.location.href first then the alert() message, I get about 15 to 20 window popping up...isn't that wierd??
This is exactly how we have it:

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

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

<!-- If the user is not logged in, not currently on the login page, 4gotten the password -->
<CFIF #session.LoggedIn IS &quot;FALSE&quot;>
  <CFIF (CGI.SCRIPT_NAME IS NOT &quot;login.cfm&quot;)
    AND (CGI.SCRIPT_NAME IS NOT &quot;results.cfm&quot;)
    AND (CGI.SCRIPT_NAME IS NOT &quot;password_help.cfm&quot;)
    
    <script>
      alert(&quot;you are being redirected&quot;);
      window.location.href = &quot;login.cfm&quot;;
    </script>

  </CFIF>
</CFIF>

ANy suggestion as to why this loops?? And why it only works fine if the login.cfm is in a directory above?? I have not failed; I merely found 100,000 different ways of not succeding...
 
Try replaceing AND with OR in the IF statment

<CFIF (CGI.SCRIPT_NAME IS NOT &quot;login.cfm&quot;)
OR (CGI.SCRIPT_NAME IS NOT &quot;results.cfm&quot;)
OR (CGI.SCRIPT_NAME IS NOT &quot;password_help.cfm&quot;)

KentH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top