Solved

cfapplication - how to keep login information for each page

Posted on 2004-10-06
10
334 Views
Last Modified: 2013-12-24
I'm using cfapplication and I need every page the user accesses, I need their name and employee number.

My cfapplication.cfm looks like this:

<!--- Create the application --->
<cfapplication name="myapp" clientmanagement="Yes" sessionmanagement="Yes" sessiontimeout="#CreateTimeSpan(0,4,0,0)#" applicationtimeout="#CreateTimeSpan(0,8,0,0)#" SETCLIENTCOOKIES="Yes">

<CFPARAM NAME="session.allowin" DEFAULT="false">

<cfif session.allowin neq "true">
      <cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">
      <cfelseif ListLast(CGI.SCRIPT_NAME, "/") EQ "mgmt_home.cfm">
      <cfelse>
      <script>
              alert("You must login to access this area!");
              self.location="login.cfm";
      </script>
      </cfif>
</cfif>

My form on the login.cfm page looks like this:

<form action="mgmt_home.cfm" method="post">
<table width="65%" cellspacing="2" cellpadding="2" align="center" bgcolor="B0C4DE">
   <tr>
      <td colspan="2" align="center" class="small">
         Please enter your AWID and password.<br>
         <img src="../images/dot_clear.gif" width="1" height="10">
      </td>
   </tr>
   <tr>
      <th align="right" class="small">Login:</th>
      <td><input type="text"
         size="15"
         maxlength="7"
         name="user_name"
         value=""
         class="smallblue"
         onFocus="this.style.border='2px solid';"
         onBlur="this.style.border='1px solid';">
      </td>
   </tr>
   <tr>
      <th align="right" class="small">Password:</th>
      <td><input type="password"
         size="15"
         maxlength="8"
         name="user_pass"
         value=""
         class="smallblue"
         onFocus="this.style.border='2px solid';"
         onBlur="this.style.border='1px solid';">                                    
      </td>
   </tr>
   <tr>
      <td colspan="2" align="right"><input type="Image" src="../images/go.gif" name="login_user" value="Log In"></td>
   </tr>
</table>
</form>

And finally...my authorized login page, mgmt_home.cfm looks like this:

<!-- BEGIN LOGIN VERIFICATION -->
<!--- Get all records from the database that match this users credentials --->
<cfquery name="qVerify" datasource="myds">
    SELECT            *
    FROM            tbl_loginmgmt
    WHERE            user_name = '#user_name#'
</cfquery>

<cfif qVerify.RecordCount>
    <!--- This user has logged in correctly, change the value of the session.allowin value --->
    <cfset session.allowin = "True">
    <!--- Now welcome user and redirect to "index.cfm" --->
<cfoutput query="qVerify">

</cfoutput>      
<cfelse>
    <!--- this user did not log in correctly, alert and redirect to the login page --->
    <script>
        alert("Your credentials could not be verified, please try again!!!");
        self.location="Javascript:history.go(-1)";
    </script>
</cfif>
<!-- END LOGIN VERIFICATION -->

Now if the user clicks on a menu item off of this page and goes to the next page, I lose the user_name information.  How do I keep the qverify query information with any page the user attempts to access?
0
Comment
Question by:Lee R Liddick Jr
  • 5
  • 4
10 Comments
 
LVL 21

Accepted Solution

by:
pinaldave earned 500 total points
ID: 12241963
Hi leerljr68,
use session management and that way you can save it...
now I have noticed that you are already using the session you can do this...

<cfset session.queryname = yoruquery>

this is what you can pass to all the pages nad you can use all the param from this session.queryname

Regards,
---Pinal
0
 

Author Comment

by:Lee R Liddick Jr
ID: 12242032
So on every page I include the statement:

<cfset session.queryname = qVerify>

qVerify being the name of my initial query on my login verification page (mgmt_home.cfm).
0
 

Author Comment

by:Lee R Liddick Jr
ID: 12242190
Or no...it would be this...

<cfset session.qVerify = form.user_name>

And I would place this on every page?
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12242484
you do not have to do that on every page... you will have to do it once where you run that query and through out the session it will be automatically be saved and you can get it on whatever page you want to use it.
Regards,
---Pinal
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 12244448
make sure cookies are enabled, if not pass the #session.urlToken# with every url, i.e. < ahref="index.cfm?#session.urlToken#">test</a>

or use #urlSessionFormat("index.cfm")#
0
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

 

Author Comment

by:Lee R Liddick Jr
ID: 12245120
I will finish trying that and testing on Thursday pinaldave...thank you much!
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12245359
no problem,
Hope that I can help you,
Regards,
---Pinal
0
 

Author Comment

by:Lee R Liddick Jr
ID: 12258684
pinaldave...I'm not getting something here...

I have application.cfm, login.cfm (which is just the login form), and mgmt_services.cfm (which is the first page the user sees when successfully logging in).  Mgmt_services.cfm is the page that also holds the query qVerify that holds the login information and the information that I want passed to every page that user accesses.

So in your example:

<cfset session.queryname = yourquery>

What does 'queryname' represent?  What does 'yourquery' represent?  And where exactly am I placing this?
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12258828
you can put that in your application.cfm
what youcan do is that yourqury is the qurey you will run and want to store in the session variable the information of the login.
the queryname will be any variable which you want to give it the name it can be same name as your query for username or anything...
0
 

Author Comment

by:Lee R Liddick Jr
ID: 12259491
My cfapplication.cfm now looks like this but it still isn't working...

<!--- Create the application --->
<cfapplication name="myname" clientmanagement="Yes"
                    sessionmanagement="Yes"
                    sessiontimeout="#CreateTimeSpan(0,4,0,0)#"
                    applicationtimeout="#CreateTimeSpan(0,8,0,0)#"
                              SETCLIENTCOOKIES="Yes">

<!--- Now define that this user is logged out by default --->
<CFPARAM NAME="session.allowin" DEFAULT="false">
<!--- Now if the variable "session.allowin" does not equal true, send user to the login page --->

<cfif session.allowin neq "true">
      <cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">
      <cfelseif ListLast(CGI.SCRIPT_NAME, "/") EQ "mgmt_home.cfm">
        <cfset session.qVerify = qVerify>
      <cfelse>
      <!--- this user is not logged in, alert user and redirect to the login.cfm page --->
      <script>
              alert("You must login to access this area!");
              self.location="login.cfm";
      </script>
      </cfif>
</cfif>
0

Featured Post

Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

Join & Write a Comment

Suggested Solutions

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

19 Experts available now in Live!

Get 1:1 Help Now