|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Show logged in user_name
I have a table with user_ID and user_name.. their session is determined on their user_id so i was wondering how i could show the user_name of those logged in...
here is my login_process page: <!--- Get all records from the database that match this users credentials ---> <cfquery name="qVerify" datasource="userLogin"> SELECT user_id, user_name, user_pass FROM registration_info WHERE email = '#email#' 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"> <cfset session.user_id = qVerify.user_id> <!--- Now welcome user and redirect to "members_only.cfm" ---> <script> alert("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("Incorrect email address or password, please try again."); self.location="javascript:history.go(-1)"; </script> </cfif> and what would i need to put for it to show their user_name |
|
#2
|
|||
|
|||
|
Could you not just set a session variable for the user name? Then you could show it anywhere you want to.
By the way, using Javascript like that to enforce security is a bad idea because Javascript can be easily disabled. I'd use a <cflocation> instead unless you really aren't worried about it.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
I am new to coldfusion so i dont know all the tags.. ill look into it right now though, thanks!
About the post though.. Would I just add: <cfset session.user_name = qVerify.user_name> under the user_ID one? How can i make it so it logs them out after a certain period of time if they dont actually log out? AND what exactly do i put to actually output the user_id or user_name? Thanks for all the help Quote:
|
|
#4
|
|||
|
|||
|
thats weird, theres 2 replies but it only says 1. *edited well now 2 when theres 3* :P
Quote:
|
|
#5
|
|||
|
|||
|
Yes you could put:
<cfset session.user_id = qVerify.user_id> <cfset session.user_name = qVerify.user_name> Session variables automatically time out after a certain period of inactivity. This time span is set in the ColdFusion administrator or in the <cfapplication> tag for the application. The value set in the CF admin is the maximum value allowed. You'd output it like this: <cfoutput>#session.user_name#</cfoutput> If you're not up to date on these kinds of things, I'd recommend Ben Forta's CF book. And keep in mind that when dealing with variables in shared scopes (session, application, and server scopes) you must start to consider threading and race conditions. Normally it's not a huge concern, in professional development it is something that must be addressed. |
|
#6
|
|||
|
|||
|
If i was logged in, and that was on the page it would output my user_name, yes.. but what if i am wanting to see the others who are logged in? like showing the user_name of all online users.. or maybe im missing something
![]() Quote:
|
|
#7
|
|||
|
|||
|
Sessions are unique to each user. Getting information about all active sessions is much more complicated. I believe there is an unsupported call that could be made to the underlying Java classes that deal with sessions. But this could (and probably will) break in CFMX 7 due out shortly.
You could also keep track of the sessions yourself, maybe setting an application variable in addition to the session data when the user logs in. Application-scoped variables are available across all user sessions. But consideration of threading issues is even more important when dealing with application variables. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Show logged in user_name |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|