An affiliate system is essential for anyone selling products online. In this article Mitchell goes behind the scenes and shows us an affiliate system from one of his eCommerce web sites.
Case Study: An Affiliate System With ASP - The ShowLogin function (Page 4 of 7 )
ShowLogin is used in combination with ProcessLogin to get the affiliates email address and password and to verify them against the database respectively. First off, the ShowLogin function displays a simple HTML form. When the login button is clicked, a small bit of JavaScript is used to make sure that both of their fields were completed:
<script language="Javascript">
function CheckForm(varForm) {
if (document.frmLogin.txtEmail.value == "") { alert('Please enter your email address (eg johndoe@hotmail.com)'); document.frmLogin.txtEmail.focus(); return false; } if (document.frmLogin.txtPassword.value == "") { alert("Please enter your password"); document.frmLogin.txtPassword.focus(); return false; } return true; } </script>
The login's <form> tag contains the onSubmit event, meaning that when the form is submitted, the JavaScript function CheckForm will be called. It also contains a where query string variable that's set to processlogin:
When the form is submitted, affiliates.asp calls the ProcessLogin function, which simply takes the affiliates email and password and checks them with a SELECT query, similar to the one shown below:
strQuery = "SELECT COUNT(*) FROM Affiliates WHERE email='" & txtEmail & "' AND password='" & txtPassword & "'"
if objRS.State = 1 then objRS.Close objRS.Open strQuery
intCount = CInt(objRS.Fields(0).value) if intCount > 0 then
'The user exists, we will set their login details 'to a session variable
'Set the cookies so the user is remembered by the login form Response.Cookies("aEmail") = Request("txtEmail") Response.Cookies("aPass") = Request("txtPassword")
end if
Response.Redirect "affiliates.asp?where=link"
else
'The user doesn't exist in the affiliates table %> <span class="blueHeader">Affiliate Not Found</span> <br><br> <span class="bodyText"> No affiliate account with the email address "<%=txtEmail%>" was found. Please click on the button below to go back and try again. <br><br> <a href="javascript:history.go(-1)"><img border="0" src="rel.gif"></a> </span> <% end if
As the code shows, a session variable called affEmail is set. Two cookie variables are also set. These are used to pre-fill the login form if the user ticked the "remember me" checkbox.
At this point the affiliate is logged in and will want to do one of three things: build links, check his click-thru rate, or check his affiliate sales. We will take a look at these functions on the next page.