Solved

Can you help me figure out what's wrong with my code?

Posted on 2003-11-12
15
355 Views
Last Modified: 2013-12-24
I have designed three pages for the user to login in, now, I have a problem. After I entered the correct username and pasword, I haven't been redirect to the character.cfm page where I should go. Can you help me?

The first page: application.cfm (part of it)

<CFAPPLICATION
    NAME="Application"
    SESSIONMANAGEMENT="Yes"
    SESSIONTIMEOUT="#CreateTimeSpan(0,0,20,0)#"
    APPLICATIONTIMEOUT="#CreateTimeSpan(0,0,20,0)#">

    <CFIF Not IsDefined('Application.DSN')>
      <!--- and if it hasn't, we set it and the default application path--->
          <CFLOCK scope="application" type="exclusive" timeout="10">
            <CFSET Application.DSN = "WDSurvey">
            <CFSET Application.AppPath = "/textile/code">

       </CFLOCK>
    </CFIF>
<CFLOCK scope="application" type="exclusive" timeout="10">
<CFSET SiteTitle="TextileSurveyPages">
</CFLOCK>

  <CFIF NOT isDefined("session.auth.isLoggedIn")>
          <CFIF #CGI.SCRIPT_NAME# is not (#Application.AppPath# & "logout.cfm")>
            <cfinclude template="login.cfm">
          <cfabort>      
        </CFIF>
  </CFIF>

The second page: (part of it)

 <cfform name="login" method="post" action="#CGI.SCRIPT_NAME#">
      Firmid: <cfinput name="firmid" type="text" Required="Yes" message="Please Enter a Firm Identification Number" maxlength="20"tabindex=1>
               Password:
                 <cfinput name="password" type="password" Required="Yes" message="Please Enter a Password" maxlength="10" tabindex=2>
                   <input  type="submit" value="Login Now" >
                   <input type="submit"  value="Reset" ></td>
                 </cfform>

The third page: (part of it)

<CFPARAM name="Form.firmid" TYPE="string">
<CFPARAM name="Form.password" Type="string">

<CFQUERY name="Checkfirmid" datasource="#Application.DSN#">
SELECT *
FROM tblTextile
WHERE Firmid='#Form.firmid#'
AND Password='#Form.password#'
</cfquery>

<CFIF Checkfirmid.RecordCount EQ 1>
<CFLOCK scope="session" timeout="10" type="exclusive">
<CFSET SESSION.Auth = StructNew()>
<CFSET SESSION.Auth.isLoggedIn = "True">
<CFSET SESSION.Auth.firmid = Checkfirmid.Firmid>
</CFLOCK>

<CFLOCK scope="application" type="readonly" timeout="10">
      <CFIF #CGI.SCRIPT_NAME# is (#Application.AppPath# & "login.cfm")>
      <CFLOCATION URL='#Application.AppPath#characteristics.cfm'>
      <CFELSE>
      <CFLOCATION URL='#CGI.SCRIPT_NAME#'>
      </cfif>
</CFLOCK>
<CFELSE>
  <p><font color="#FF0000">Your username or password did not match anything in the
    database. Please try again! </font></p>

</cfif>

Thanks a lot for your help!!




0
Comment
Question by:xiaobing
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
  • +2
15 Comments
 
LVL 6

Expert Comment

by:PE_CF_DEV
ID: 9735131
Try outputing this: #CGI.SCRIPT_NAME#  #evaluate('#Application.AppPath#login.cfm')#
and see if they are really matching.
0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 9735303
try using this for your login.cfm page

<CFIF NOT isDefined("form.password")>
 <cfform name="login" method="post" action="#CGI.SCRIPT_NAME#">
     Firmid: <cfinput name="firmid" type="text" Required="Yes" message="Please Enter a Firm Identification Number" maxlength="20"tabindex=1>
               Password:
                 <cfinput name="password" type="password" Required="Yes" message="Please Enter a Password" maxlength="10" tabindex=2>
                   <input  type="submit" value="Login Now" >
                   <input type="submit"  value="Reset" ></td>
                 </cfform>

<cfelse>

<CFPARAM name="Form.firmid" TYPE="string">
<CFPARAM name="Form.password" Type="string">

<CFQUERY name="Checkfirmid" datasource="#Application.DSN#">
SELECT *
FROM tblTextile
WHERE Firmid='#Form.firmid#'
AND Password='#Form.password#'
</cfquery>

<CFIF Checkfirmid.RecordCount EQ 1>
<CFLOCK scope="session" timeout="10" type="exclusive">
<CFSET SESSION.Auth = StructNew()>
<CFSET SESSION.Auth.isLoggedIn = "True">
<CFSET SESSION.Auth.firmid = Checkfirmid.Firmid>
</CFLOCK>

<CFLOCK scope="application" type="readonly" timeout="10">
     <CFIF #CGI.SCRIPT_NAME# is (#Application.AppPath# & "login.cfm")>
     <CFLOCATION URL='#Application.AppPath#characteristics.cfm'>
     <CFELSE>
     <CFLOCATION URL='#CGI.SCRIPT_NAME#'>
     </cfif>
</CFLOCK>
<CFELSE>
  <p><font color="#FF0000">Your username or password did not match anything in the
    database. Please try again! </font></p>

</cfif>

</CFIF>
0
 
LVL 11

Expert Comment

by:hart
ID: 9737297
i would have gone for cookies...
because sessions give problem with poxy servers..

the usernames and other stuff get interchanged if u r browsing behind a proxy server.

the best way to avoid this is use cookies.

i would keep the application file plain and simple with just 1 line
<CFAPPLICATION NAME="AM_1_1000000001" CLIENTMANAGEMENT="Yes">

and then i would have a login page...
where the user will enter the username and password

then from there i will go to an intermediate page called checkLogin.cfm

where i will check wether the user is a valid one or not and then the following part

<cfif query recordcount not 0>
if u want a permanent cookie then
<CFCOOKIE NAME="MyCookie" VALUE="#Queryname.fieldname#~#Queryname.fieldname#" EXPIRES="NEVER">

else if u need a temperary cookie then
<CFCOOKIE NAME="MyCookie" VALUE="#Queryname.fieldname#~#Queryname.fieldname#" EXPIRES="NOW">

<CFHEADER NAME="Refresh" VALUE="0; URL=characteristics.cfm">

<cfelse>
redirect him back to login page  and show invalid user there
</cfif>            


and u can read the cookie values by writing #ListGetAt(Cookie.MyCookie,1,'~')# and #ListGetAt(Cookie.MyCookie,2,'~')#

Regards
Hart
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 17

Accepted Solution

by:
anandkp earned 500 total points
ID: 9737370
Considering that ur query is working fine

wont this code work for u

<CFIF Checkfirmid.RecordCount EQ 1>
      <CFLOCK scope="session" timeout="10" type="exclusive">
            <CFSET SESSION.Auth = StructNew()>
            <CFSET SESSION.Auth.isLoggedIn = "True">
            <CFSET SESSION.Auth.firmid = Checkfirmid.Firmid>
      </CFLOCK>      
      <CFLOCATION URL='#Application.AppPath#characteristics.cfm'>            
<CFELSE>
<P><FONT color="#FF0000">Your username or password did not match anything in the
    database. Please try again!</FONT></P>
</CFIF>

just a thought !
0
 

Author Comment

by:xiaobing
ID: 9741599
Can you tell me how to output?

Try outputing this: #CGI.SCRIPT_NAME#  #evaluate('#Application.AppPath#login.cfm')#
and see if they are really matching.
0
 
LVL 6

Expert Comment

by:PE_CF_DEV
ID: 9741717
Just do
<cfoutput>#CGI.SCRIPT_NAME#  #evaluate('#Application.AppPath#login.cfm')#</cfoutput>

from your 3rd page

<CFLOCK scope="application" type="readonly" timeout="10">
     <CFIF #CGI.SCRIPT_NAME# is (#Application.AppPath# & "login.cfm")>
     <CFLOCATION URL='#Application.AppPath#characteristics.cfm'>
     <CFELSE>
     <CFLOCATION URL='#CGI.SCRIPT_NAME#'>
     </cfif>
</CFLOCK>


Change to:
<CFLOCK scope="application" type="readonly" timeout="10">
     <CFIF #CGI.SCRIPT_NAME# is (#Application.AppPath# & "login.cfm")>
     <CFLOCATION URL='#Application.AppPath#characteristics.cfm'>
     <CFELSE>
<cfoutput>#CGI.SCRIPT_NAME#  #evaluate('#Application.AppPath#login.cfm')#</cfoutput>
     <!--- <CFLOCATION URL='#CGI.SCRIPT_NAME#'> --->
     </cfif>
</CFLOCK>

or put it somewhere else :)
0
 

Author Comment

by:xiaobing
ID: 9741949
I did. The result is

 /textile/code/login.cfm

it looks it's correct. But it still didn't work. After I entered the correct firmid and username, I was redirected to login.page again.

I really don't know what's wrong with it now.

Xiao bing
0
 
LVL 6

Expert Comment

by:PE_CF_DEV
ID: 9742056
when you enter the login name and stuff the form submits to itself, I assume this is login.cfm

I don't see when the 3rd page is getting used.

The third page defines : session.auth.isLoggedIn

but in application.cfm it looks to see if this is defined. If it isn't defined you are taken to the second page.
0
 

Author Comment

by:xiaobing
ID: 9742099
As PE_CF_DEV said, I tested the path if it's correct.

When I used <cfoutput>#CGI.HTTP_HOST##CGI.PATH_INFO# </cfoutput>

I got the correct path that I want. So,  I copied  #CGI.HTTP_HOST##CGI.PATH_INFO#  and replace "/textile/code" in application.cfm. The new code like these:
 <CFSET Application.AppPath = #CGI.HTTP_HOST##CGI.PATH_INFO#  >

In my understanding, it should work. But when I run it, I got error message like this:

Invalid parser construct found on line 19 at position 42. ColdFusion was looking at the following text:
#
Invalid expression format. The usual cause is an error in the expression structure.

Can you tell me what's the problem? Thanks
0
 

Author Comment

by:xiaobing
ID: 9742245
For this problem, can yo tell me how to change it? I deleted <CFSET SESSION.isLoggedIn = "True">, but it still didn't work.


when you enter the login name and stuff the form submits to itself, I assume this is login.cfm

I don't see when the 3rd page is getting used.

The third page defines : session.auth.isLoggedIn

but in application.cfm it looks to see if this is defined. If it isn't defined you are taken to the second page.
0
 

Author Comment

by:xiaobing
ID: 9742267
I have found the  syntax error in <CFSET Application.AppPath = #CGI.HTTP_HOST##CGI.PATH_INFO#  >. But even if I added #   # and deleted  <CFSET SESSION.isLoggedIn = "True">, it still didn't work.

Help!
0
 
LVL 17

Expert Comment

by:anandkp
ID: 9745216
Did u try - what i had suggested ??? did it help ???
0
 
LVL 11

Expert Comment

by:hart
ID: 9745436
<CFSET Application.AppPath = CGI.HTTP_HOST & CGI.PATH_INFO>

Regards
Hart
0
 

Author Comment

by:xiaobing
ID: 9748005
As I said before, if there are several pages, I need to track the user's id and password, which one is better, session or cookie?
0
 
LVL 17

Expert Comment

by:anandkp
ID: 9752855
I wld use Cookies !
[ Browser based ]- so once the user leaves teh site - they exprire automatically.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
What You Need to Know when Searching for a Webhost Provider
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 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