更改会话变量输出
我使用 Dreamweaver CS5 和 Coldfusion 9 来构建一个动态网站。我有一个 MS Access 数据库,用于存储登录信息,其中包括 ID、全名、名字、姓氏、用户名、密码、访问级别。
我的问题是这样的: 我目前有会话变量来跟踪用户名进入登录页面时的情况。不过,我想使用该用户名来提取用户的全名以在整个网页中显示并用于查询数据。当他们没有在登录页面上输入全名而只输入用户名和密码时,如何更改会话变量以读取该变量。
我在下面列出了我的登录信息代码,如果需要任何其他信息,请告诉我。
这是 FullName 值所在的路径 数据源“Access”表“Logininfo”字段“FullName” 我希望 FullName 根据从登录页面提交的用户名是唯一的。
对于我可能犯的任何菜鸟错误,我提前表示歉意,我对此很陌生,但学得很快!哈。
<cfif IsDefined("FORM.username")>
<cfset MM_redirectLoginSuccess="members_page.cfm">
<cfset MM_redirectLoginFailed="sorry.cfm">
<cfquery name="MM_rsUser" datasource="Access">
SELECT FullName, Username,Password,AccessLevels FROM Logininfo WHERE Username=<cfqueryparam value="#FORM.username#" cfsqltype="cf_sql_clob" maxlength="50"> AND Password=<cfqueryparam value="#FORM.password#" cfsqltype="cf_sql_clob" maxlength="50">
</cfquery>
<cfif MM_rsUser.RecordCount NEQ 0>
<cftry>
<cflock scope="Session" timeout="30" type="Exclusive">
<cfset Session.MM_Username=FORM.username>
<cfset Session.MM_UserAuthorization=MM_rsUser.AccessLevels[1]>
</cflock>
<cfif IsDefined("URL.accessdenied") AND false>
<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>
I am using Dreamweaver CS5 with Coldfusion 9 to build a dynamic website. I have a MS Access Database that stores login information which includes ID, FullName, FirstName, LastName, Username, Pawword, AcessLevels.
My question is this:
I currently have session variable to track the Username when it is entered into the login page. However I would like to use that Username to pull the User's FullName to display throughout the web pages and use for querying data. How do I change the session variable to read that when they are not entering their FullName on the login page but only Username and password.
I have listed my login information code below if there is any additional information needed please let me know.
This is the path for which the FullName values reside DataSource "Access" Table "Logininfo" Field "FullName" I want the FullName to be unique based on the Username submitted from the Login page.
I apologize in advance for any rookie mistake I may have made I am new to this but learning fast! Ha.
<cfif IsDefined("FORM.username")>
<cfset MM_redirectLoginSuccess="members_page.cfm">
<cfset MM_redirectLoginFailed="sorry.cfm">
<cfquery name="MM_rsUser" datasource="Access">
SELECT FullName, Username,Password,AccessLevels FROM Logininfo WHERE Username=<cfqueryparam value="#FORM.username#" cfsqltype="cf_sql_clob" maxlength="50"> AND Password=<cfqueryparam value="#FORM.password#" cfsqltype="cf_sql_clob" maxlength="50">
</cfquery>
<cfif MM_rsUser.RecordCount NEQ 0>
<cftry>
<cflock scope="Session" timeout="30" type="Exclusive">
<cfset Session.MM_Username=FORM.username>
<cfset Session.MM_UserAuthorization=MM_rsUser.AccessLevels[1]>
</cflock>
<cfif IsDefined("URL.accessdenied") AND false>
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看起来查询已经在提取 FullName,因此如果您想要一个包含 FullName 值的会话变量。
你有这个代码:
将其更改为类似以下内容(应该可以工作一段时间没有起诉 CF,所以基于记忆,未测试)
这将添加 Session.FullName,您可以在站点的其他位置引用它。用户登录后,它应该出现在任何页面上,因此在使用该值之前,您必须在不需要登录的页面上检查它是否存在。
请注意:您使用的代码是由 Dreamweaver 登录服务器行为自动生成的,我建议的更改很可能会破坏该服务器行为的检查或重新应用。如果发生这种情况,您可以通过删除添加的代码行并在进行所需的任何更改后重新添加它来恢复。您可能需要确保 FullName 位于查询 SELECT 语句中,以确保 FullName 可用。
I looks like the query is already pulling FullName, so if you want a session variable that contains the value of FullName.
You have this code:
Change it to something like the following (should work haven't sued CF in a while, so based on memory, not tested)
That will add Session.FullName, and you can reference that elsewhere in your site. It should be present on any page after the user has logged in, so you'd have to check for it's existence on pages that don't require log in before using that value.
Please note: the code you're using is auto-generated by a Dreamweaver log in server behavior, and it's quite possible that the changes I'm suggesting will break the inspection or reapplication of that server behavior. If that happens, then you may be able to recover by removing the added line of code and the re-adding it after making any changes you you need to make. You may need to make sure that FullName is in the query SELECT statement to make sure that FullName will be available.