Published:
23 Oct 2003
|
Abstract
Many websites and portals allow you to personalize the look of the site for the benefit of the user and themselves. Personalizing a site can go from very simple to very hard, very quickly. This article will look at one of the more simple ways. |
|
by . .
Feedback
|
Average Rating:
Views (Total / Last 10 Days):
25475/
37
|
|
|
Introduction |
Personalization
Published 12/19/01 - For
Classic ASP
Introduction
Many websites and portals allow
you to personalize the look of the site for the benefit of the user and
themselves. Personalizing a site can go from very simple to very hard, very
quickly. This article will look at one of the more simple ways. It will take a
site and allow the user to personalize what items can be seen on the page
(news, stocks, technology etc.) and then the settings will be stored in a
Session Variable. See it running
here.
|
Getting Started |
Getting Started
The way that the personalization
(that we are going to use) works is by storing a long (10 character) string of
just numbers. The string would look something like - 0001010001. Then the page
looks at that string and pulls it apart to then find out what you want
displayed and then shows it. This seems complicated but its quite simple. For
the purposes of this demonstration, the personalization string will be stored
in a Session variable, usually you would store it in a cookie or a database
(or both), but lets keep it simple.
First I just created the page for
the information, plain and simple HTML. You should put things like includes in
the appropriate places if you want. The page I did looks like this -
Then I moved onto the ASP Coding.
I began to split the page up into Subroutines of each section. The following
is the one for the index. There were also ones for each of the sections, The
header, footer and the middle bit between the two columns.
Sub page_in()
%>
<font face="Verdana" size="5" color="#800000">InfoStuff
Index</font><hr noshade color="#C0C0C0" size="1">
<font face="Arial" size="2">News<br>
Computing<br>
Science<br>
Internet<br>
Stock Markets<br>
About<br>
<a href="pers.asp">Personalize</a><br>
</font>
<%
End Sub |
These subs can be called whenever
you want that section of the page to appear. We'll leave it at that for now.
We currently have -
-
The complete front page and all
of the information that could be on it.
-
We have split it up into subs,
one for each section as well as header, footer and the inner bit (this is
just a '</td><td>' type thing)
|
Personalisation |
Personalization
Next, is the personalization page,
this is just a form -
Each checkbox is named ind, sto,
tod, tec and sci (to represent Index, Stocks, Today, Technology and Science
respectively. It submits to a page called 'dopers.asp'. Which is just code -
<%
Dim pers
If Len(Request.QueryString("ind")) Then
pers = "01"
Else
pers = "00"
End If
If Len(Request.QueryString("sto")) Then
pers = pers & "01"
Else
pers = pers & "00"
End If
If Len(Request.QueryString("tod")) Then
pers = pers & "01"
Else
pers = pers & "00"
End If
If Len(Request.QueryString("tec")) Then
pers = pers & "01"
Else
pers = pers & "00"
End If
If Len(Request.QueryString("sci")) Then
pers = pers & "01"
Else
pers = pers & "00"
End If
Session("pers") = pers
Response.Redirect("infostuff.asp")
%> |
Which checks each checkbox to see weather it
was filled in, if so, it adds '01' to the personalization string and if not it
adds '00' to the string. This created the 'pers' string which is then assigned
to the Session variable of the same name. The user is then redirected back to
the main page (infostuff.asp).
|
Back to InfoStuff |
Back to InfoStuff
By now, the user would have created a string
like 0001010001 and has been sent back to infostuff.asp. Now we need to sort
out this string -
If Len(Session("pers"))
Then
Dim pers
Dim ind
Dim sto
Dim tod
Dim tec
Dim sci
pers = Session("pers")
ind = Mid(pers, 1, 2)
sto = Mid(pers, 3, 2)
tod = Mid(pers, 5, 2)
tec = Mid(pers, 7, 2)
sci = Mid(pers, 9, 2)
'more to come |
This checks to see if the personalization
string is there and then chops it up into the individual parts that were
assigned earlier.
Next we need to call the appropriate subs, depending on what the user chose to
display -
Call page_top
If ind = "01" Then
Call page_in
End If
If sto = "01" Then
Call page_st
End If
Call page_inner
If tod = "01" Then
Call Page_to
End If
If tec = "01" Then
Call page_te
End If
If sci = "01" Then
Call page_sc
End If
Call page_end |
So - If the user chose to view only Technology
and Stocks, then the string would look like - 0001000100. Then when it is
broken up, only stocks and technology are 01 (the rest are 00). Then these if
statements would only call page_top (always there), page_st (stocks),
page_inner (always there), page_te (technology) and page_end (always there).
Else
Call page_top
Call page_in
Call page_st
Call page_inner
Call Page_to
Call page_te
Call page_sc
Call page_end
End If |
And if they haven't personalized, then the
normal page is displayed.
|
Summary |
Summary
Experiment with the
sample page and
see what you can get out -
I know that there are other things that I could
have done (eg. have many Session Variables for each customization). But I
wanted a quick and dirty way to personalize something. You can also
personalize in different ways and do other things such as the positioning of
the objects. But that's another article.
|
|
|
User Comments
No comments posted yet.
|
Product Spotlight
|
|