Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2003-11-12
15
Medium Priority
?
358 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
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

618 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