Solved

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

Posted on 2003-11-12
15
349 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
  • 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
 
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now