Link to home
Start Free TrialLog in
Avatar of Zac123
Zac123Flag for United Kingdom of Great Britain and Northern Ireland

asked on

help needed with cfapplication

What do i need to do inorder to display on my web page the current user who is signed in?

ive looked into it online and discovered that i need to have; sessionsenabled="yes" in my cfapplication but thats as much as i can find out.

could someone please give me an A,B,C step by step of what to do please.
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

frist step

<cfapplication name="" sessionmanagement="yes"> in app.cfm

then in your login.cfm
query to check in authentication....
<cfquery name="qryLogin" datasource="#application.sDataSource#">
        get all the details of user if authentication passes
  </cfquery>

then write the followign statements to keep the values of the logged in user in to session variables
      <cflock scope="session" timeout="10">
       <cfscript>
            session.userid = qryLogin.id;
            session.username = qryLogin.name;
            session.location = qryLogin.location;
            
       </cfscript>      
      </cflock>

in pages you want you can display name  just say #session.username# and and want to diaply location #session.location#
 
 
Avatar of Zac123

ASKER

ok, thanks for your help so far. just need a bit more from you.

this is my application.cfm so far do i need to add anything else?

<cfapplication sessionmanagement="yes"
setclientcookies="yes"
name="user_details"
sessiontimeout="#CreateTimeSpan(0,0, 20, 0)#"
sessionmanagement="yes"


this is my login page so far do i need to add anything else?


<cfif IsDefined("FORM.email")>
  <cfset MM_redirectLoginSuccess="../index.cfm">
  <cfset MM_redirectLoginFailed="failedlogin.cfm">
  <cfquery  name="MM_rsUser" datasource="ukdiscountproducts">
  SELECT email,user_password,user_level FROM registered_users WHERE email=<cfqueryparam value="#FORM.email#" cfsqltype="cf_sql_clob" maxlength="255"> AND user_password=<cfqueryparam value="#FORM.user_password#" cfsqltype="cf_sql_clob" maxlength="255">
  </cfquery>
  <cfif MM_rsUser.RecordCount NEQ 0>
    <cftry>
    <cflock scope="Session" timeout="30" type="Exclusive">
      <cfset Session.MM_Username=FORM.email>
      <cfset Session.MM_UserAuthorization=MM_rsUser.user_level[1]>
    </cflock>
    <cfif IsDefined("URL.accessdenied") AND true>
      <cfset MM_redirectLoginSuccess=URL.accessdenied>
    </cfif>
    <cflocation url="#MM_redirectLoginSuccess#" addtoken="no">
    <cfcatch type="Lock"><!--- code for handling timeout of cflock --->
    </cfcatch>
    </cftry>
  </cfif>
  <cflocation url="#MM_redirectLoginFailed#" addtoken="no">
  <cfelse>
  <cfset MM_LoginAction=CGI.SCRIPT_NAME>
  <cfif CGI.QUERY_STRING NEQ "">
    <cfset MM_LoginAction=MM_LoginAction & "?" & XMLFormat(CGI.QUERY_STRING)>
  </cfif>
</cfif>

<cfquery name="qryLogin" datasource="#application.sDataSource#">
 SELECT *
 FROM registered_users
  </cfquery>



so where about does this bit go??
<cflock scope="session" timeout="10">
       <cfscript>
            session.userid = qryLogin.id;
            session.username = qryLogin.name;
            session.location = qryLogin.location;
           
       </cfscript>      
      </cflock>


thanks
ASKER CERTIFIED SOLUTION
Avatar of SRIKANTH MADISHETTI
SRIKANTH MADISHETTI
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial