Solved

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

Posted on 2003-11-12
15
352 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

825 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