Copy link to clipboard
Copied
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!!
Copy link to clipboard
Copied
Use the session variable you created and forget about url variables.
Copy link to clipboard
Copied
I am not yet an expert coder... can you give me a code example of pulling from the session variable?
Copy link to clipboard
Copied
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