I have created a log in feature as follows. I now want to display username on top corner of every page they visit. Will you tell me how I do that?
Application.cfm
<!--- Create the application --->
<cfapplication name="MyApp" clientmanagement="Yes"
sessionmanagement="Yes"
sessiontimeout="#CreateTimeSpan(0,0,15,0)#"
applicationtimeout="#CreateTimeSpan(0,2,0,0)#">
<!--- 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 --->
<!---
the other thing you must check for is if the page calling this application.cfm is the "login.cfm" page
and the "Login_process.cfm" page since the Application.cfm is always called, if this is not checked
the application will simply Loop over and over. To check that, you do the following call
--->
<cfif session.allowin neq "true">
<cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">
<cfelseif ListLast(CGI.SCRIPT_NAME, "/") EQ "login_process.cfm">
<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>
"login.cfm"
<form action="login_process.cfm" method="post">
Username: <input type="text" name="user_name" value=""><BR>
Password: <input type="password" name="user_pass" value=""><BR>
<input type="submit" name="login_user" value="Log In"><BR>
</form>
"login_process.cfm"
<!--- Get all records from the database that match this users credentials --->
<cfquery name="qVerify" datasource="userLogin">
SELECT user_name, user_pass
FROM tblAdmins
WHERE user_name = '#user_name#'
AND user_pass = '#user_pass#'
</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 "members_only.cfm" --->
<script>
alert("Welcome user, you have been successfully logged in!");
self.location="/members_only.cfm";
</script>
< 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>
Application.cfm
<!--- Create the application --->
<cfapplication name="MyApp" clientmanagement="Yes"
sessionmanagement="Yes"
sessiontimeout="#CreateTimeSpan(0,0,15,0)#"
applicationtimeout="#CreateTimeSpan(0,2,0,0)#">
<!--- 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 --->
<!---
the other thing you must check for is if the page calling this application.cfm is the "login.cfm" page
and the "Login_process.cfm" page since the Application.cfm is always called, if this is not checked
the application will simply Loop over and over. To check that, you do the following call
--->
<cfif session.allowin neq "true">
<cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">
<cfelseif ListLast(CGI.SCRIPT_NAME, "/") EQ "login_process.cfm">
<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>
"login.cfm"
<form action="login_process.cfm" method="post">
Username: <input type="text" name="user_name" value=""><BR>
Password: <input type="password" name="user_pass" value=""><BR>
<input type="submit" name="login_user" value="Log In"><BR>
</form>
"login_process.cfm"
<!--- Get all records from the database that match this users credentials --->
<cfquery name="qVerify" datasource="userLogin">
SELECT user_name, user_pass
FROM tblAdmins
WHERE user_name = '#user_name#'
AND user_pass = '#user_pass#'
</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 "members_only.cfm" --->
<script>
alert("Welcome user, you have been successfully logged in!");
self.location="/members_only.cfm";
</script>
< 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>