Solved

cfapplication - how to keep login information for each page

Posted on 2004-10-06
10
338 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
[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
  • 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
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)

 
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
 

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

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

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…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

688 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