Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Passing Username from Login for Personalized Pages

Guest
Aug 03, 2010 Aug 03, 2010

I am using the following code within my login process page. The code works correctly in loging in a user but does not work caring the entered #Username# to the site. I do not think I am using (self.location="/secureindex.cfm?Username=#Username#";) correctly. Any suggestions...on my recieving page I have a query using the passed #Username# to load the persons first and last name into a welcome message. I will also be using the Username to record any edits the user makes to the site.

What am I doing wrong? My full code is....

<cfquery name="qVerify" datasource="MyDatasource">
    SELECT             Username, Password
    FROM                Clienttable
    WHERE              UserName = '#Username#'
                     AND Password = '#Password#'
</cfquery>

<cfif qVerify.RecordCount>
    <cfset session.allowin = "True">
    <cfset session.Username = qVerify.Username>
    <script>
         self.location="/secureindex.cfm?Username=#Username#";
    </script>
< cfelse>
    <script>
        alert("My Alert");
        self.location="Javascript:history.go(-1)";
    </script>
</cfif>

Thanks so much!!

TOPICS
Database access
973
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 04, 2010 Aug 04, 2010

Use the session variable you created and forget about url variables.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 04, 2010 Aug 04, 2010

I am not yet an expert coder... can you give me a code example of pulling from the session variable?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 05, 2010 Aug 05, 2010
LATEST

Instead of referencing #URL.Username# you would reference #Session.Username#. One way to do it would be something like:


<cfif IsDefined("Session.Username")>

     <cfoutput>Hello, #Session.Username#!

</cfif>

A couple quick notes:

If you're not properly scoping your variables (e.g. if you're doing Hello, #Username# instead of Hello, #URL.Username# or #Session.Username#) you should probably stop doing that ASAP...it will get you into trouble sooner or later.

You can always just use cflocation instead of the javascript self.location. I don't know offhand if using the javascript self.location with a CF variable will automatically evaluate the ColdFusion variable or not...to be safe, though, you might want to put all that in a cfoutput block so ColdFusion can evaluate the variable and pass it along.

HTH

~ Amanda

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources