#native_company# #native_desc#

Mass Customization Page 2

By Jim King
on November 2, 2000

Now that we have database setup, we are ready to get started. Lets review the class file that will be used to generate what I call a lead.
This class sets a cookie to identify the visitor on subsequent occasions and then stores all of the information that we gather into the leads table, indexed by the cookie. To use this class, just add the following code to the top of any page
that you would like to customize:


mylead = new lead("dbhost""database""dbusername""dbpassword""leadstablename");

if(!isset($HTTP_COOKIE_VARS[lead])) {

$sid $mylead->setCookie();

} else {

$thelead $mylead->preloadInfo$HTTP_COOKIE_VARS[lead] );



What this code does is:
Line 1: Instantiate the class.
Line 3: Check to see if the cookie has already been set. If it has been set, skip to line 10. If not, set the cookie.
Line 9: Pre-load all the information that we have on the lead into the $thelead array. This array will look exactly
like the database table.
If you have defined the columns email, state, and zip in the database, then you can access that information with the following code:


$email $thelead[email];

$state $thelead[state];

$zip $thelead[zip];


Since the database will contain no information on a visitor (or “lead”) if the cookie has not been set, that is where things
end. If the cookie does exist, then we retrieve all the information that we have on the visitor and store it to an array named $thelead. In our example, the only column in the leads table is state. Therefore, the $thelead array should only contain the element state.
Now, there are a couple things to note at this point. If you are using php3, you will have to retrieve this information from the database for
every page you intend on using it for. In php4, we can use sessions and set a session variable named $thelead. Then, the $thelead array will be available on each page the user visits. In the examples file, I have provided an example for both php3 and php4.