?
Solved

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

Posted on 2003-11-12
15
Medium Priority
?
357 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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 17

Accepted Solution

by:
anandkp earned 2000 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

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 …
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

743 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