Skip to main content
August 4, 2010
Question

Passing Username from Login for Personalized Pages

  • August 4, 2010
  • 1 reply
  • 1020 views

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!!

This topic has been closed for replies.

1 reply

Inspiring
August 4, 2010

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

August 4, 2010

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

August 5, 2010

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