After this line of code:
<cfif Password eq #Password# and UserName eq #UserName#>
If this info is right I want to Display a page called GetPictureFromUser. How do I do this?
After this line of code:
<cfif Password eq #Password# and UserName eq #UserName#>
If this info is right I want to Display a page called GetPictureFromUser. How do I do this?
Brief troubleshooting and a safer pattern to follow, given ’s original check and ’s suggestion to either inline content or send a redirect.
The difference in behavior is simple: an inline include merges another template into the current server response, so content appears on the same page. A redirect instructs the browser to request a different URL, so the redirect header must be sent before any page output. Common causes of a “blank page” when redirecting: the redirect runs after output has already started (for example, inside a query-driven output block), the redirect runs repeatedly inside a loop, or the target path is wrong.
Two important fixes that are often missed: scope variables explicitly (don’t compare two identically named, unscoped variables) and avoid doing redirect logic inside a CFOUTPUT loop. A better flow is: fetch the user row by username (use cfqueryparam), check recordcount, compare the stored password (preferably a hash) to the submitted value, then issue the redirect and abort processing.
Example pattern:
<!--- fetch user safely --->
<cfquery name="qUser" datasource="myDSN">
SELECT password_hash
FROM users
WHERE username = <cfqueryparam value="#FORM.username#" cfsqltype="cf_sql_varchar">
</cfquery>
<!--- check and redirect before any other output --->
<cfif qUser.recordcount EQ 1 AND qUser.password_hash EQ FORM.password>
<cflocation url="/GetPictureFromUser.cfm" addtoken="no">
<cfabort>
</cfif> Additional tips: confirm the target file path exists and watch the browser’s Network/DevTools for a 3xx redirect response; use cfqueryparam to prevent SQL injection; store and compare password hashes rather than plaintext; and temporarily log or dump scoped values (not raw passwords) while debugging.
Jump to Post— dazzlindonna 0<cfif Password eq #Password# and UserName eq #UserName#>
<cfinclude template="yourpagetoinclude.cfm">
<cfelse>
<cflocation url="yourloginpage.cfm">
</cfif>
<cfif Password eq #Password# and UserName eq #UserName#>
<cfinclude template="yourpagetoinclude.cfm">
<cfelse>
<cflocation url="yourloginpage.cfm">
</cfif>
What is the difference between the template and using the url. The template worked although it displayed the information the same page which I guess is fine. The url displayed a blank page.
<cfoutput Query = "login">
<cfif Password eq #Password# and UserName eq #UserName#>
<cfinclude template="GetPictureFromUser.cfm">
<cfelse>
<cflocation url="SignIn.cfm">
</cfif>
</cfoutput>
Just depends how you want to do it - up to you. Either display the info on the same page using cfinclude or send them off to another page using cflocation. Whatever pleases you.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.