Home arrow ASP arrow Page 3 - Case Study: An Affiliate System With ASP

Case Study: An Affiliate System With ASP

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.

Author Info:
By: Mitchell Harper
Rating: 5 stars5 stars5 stars5 stars5 stars / 55
June 17, 2002
  1. · Case Study: An Affiliate System With ASP
  2. · Project Overview
  3. · The ASP code
  4. · The ShowLogin function
  5. · Generating links
  6. · Tracking Links
  7. · Conclusion

print this article

Case Study: An Affiliate System With ASP - The ASP code
(Page 3 of 7 )

TechBuy is driven by ASP 3.0, MSXML4, VB, COM+ and an SQL Server 2000 database. The affiliates program needed several different modules, each of which would be represented as an ASP function. These modules are:
  • Affiliate Signup: This function accepts the details of an affiliate and stores them in the database.
  • Affiliate Login: Once signed up, an affiliate can login to access his affiliate statistics as well as the page to generate links, banners, etc.
  • Link Generator: The TechBuy affiliate program allows its affiliates to choose from a wide range of both text and banner links for their site. Affiliates can link to individual products and categories, or they can choose from any of the 8 pre-made affiliate banners.
  • Click-Thru Reports: After affiliates have taken their tracking code, this function allows the affiliate to see the number of click-thrus from visitors to their site. These results can be viewed for last week, last month, or between particular dates.
  • Sales Reports: Allows affiliates to view how many sales have resulted from their visitorís click-thrus to the TechBuy web site.
Before we continue, it's important to know that all of the functionality for the TechBuy affiliates program is contained in one file called affiliates.asp. Each module is represented as a function and a select case statement is used in combination with a Request variable to determine which function should be called, like this:

where = Request("where")

select case where
case "what"
case "join"
case "joinfinal"
case "login"
case "processlogin"
case "link"
if intAffId > 0 then
end if
case "genlinks"
if intAffId > 0 then
end if
case "gencatlinks"
if intAffId > 0 then
end if
case "report"
if intAffId > 0 then
end if
case "ctreport"
if intAffId > 0 then
end if
case "sreport"
if intAffId > 0 then
end if
case else
end select

Let's now take a look at the code required to create some of the modules.

Affiliate Signup
Before an affiliate can get the required linking code, he obviously needs an affiliate ID. The ShowJoin function displays a simple HTML form that gets the users contact details as well as the details of his site, etc. 

This users details are collected and passed back to affiliates.asp. A hidden form variable called where is set to joinfinal and looks like this:

<input type="hidden" name="where" value="joinfinal">

By sending this hidden form variable, affiliates.php will call the ProcessJoin function, which takes the affiliates details from the Request collection and spits them into the SQL Server 2000 database.

The affliates database for TechBuy contains three tables:
  • Affiliates: Contains the details of each affiliate including their email address and contact details.
  • AffiliatePayments: Tracks payments for each affiliate. Payments are made on a monthly basis.
  • AffilaiteHits: Tracks the click-thrus from the affiliates site to TechBuy. Each record includes the visitors IP address, affiliate ID and date.
The ProcessJoin function starts out with some simple value retrievals from the Request collection:

txtFName = Replace(Request("txtFName"), "'", "''")
txtLName = Replace(Request("txtLName"), "'", "''")
txtEmail = Replace(Request("txtEmail"), "'", "''")
txtPassword = Replace(Request("txtPassword"), "'", "''")
txtVPassword = Replace(Request("txtVPassword"), "'", "''")
txtPhone = Replace(Request("txtPhone"), "'", "''")
txtFax = Replace(Request("txtFax"), "'", "''")
txtAddress1 = Replace(Request("txtAddress1"), "'", "''")
txtAddress2= Replace(Request("txtAddress2"), "'", "''")
txtSuburb = Replace(Request("txtSuburb"), "'", "''")


From here, a simple error checking routine makes sure that the user has completed the form correctly:

txtErr = ""

if txtFName = "" then txtErr = txtErr & "<li>You didn't enter your first name</li>"

if txtLName = "" then txtErr = txtErr & "<li>You didn't enter your last name</li>"

if txtPassword = "" then txtErr = txtErr & "<li>You didn't enter a password</li>"

if txtPassword <> txtVPassword AND txtPassword <> "" then txtErr = txtErr & "<li>Your passwords dont match</li>"

txtErr = txtErr & "</ul>"

if txtErr <> "<ul></ul>" then

'An error occured, display the errors
<span class="blueHeader">All Fields Not Complete!</span><br><br>
<span class="bodyText">
Some of the fields for the affiliate subscription form have not
been completed. Please review the list of incomplete fields below
and then click on the "Try Again" button and complete them.
<span class="FrontCS"><%=txtErr%></span>
<p style="margin-left:10">
<a href="javascript:history.go(-1)"><img border="0" src="rel.gif"></a>


If all fields are complete, then an insert query is executed against the database to add the affiliates details to the affiliates table.

If the INSERT query is performed successfully, then an email is composed and sent to the affiliate. This email contains their account details and the link to where they can login:

dim objMail
set objMail = Server.CreateObject("CDONTS.NewMail")

objMail.To = txtEmail
objMail.From = "TechBuy Affiliates Team <affiliates@techbuy.com.au>"
objMail.Subject = "TechBuy Affiliate Account Details"

'Generated from form values
objMail.Body = strEmail

The email sent to the affiliate contains a link that points to http://www.techbuy.com.au/affiliates.asp?where=login. This causes the ShowLogin function to be called, which is what we will look at next.
blog comments powered by Disqus

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials