#!D:\Perl\bin\perl.exe -w use CGI qw(:standard); use CGI::Cookie; |
# # frontpage.pl # # Sample Perl script that uses cookies # to create custom content for each M-Business Anywhere user. # # This is your basic Movie Reviews front page. It looks up # the user's preferences for movies he likes, and # provides links to, different movie reviews if they # fit into his list of categories. If this is the user's # first time here, it provides him with some default # categories. |
# # The basic strategy is this: We look for a cookie called # moviereviewID. # # If it exists, we take the value of that cookie (the # user's ID) and look it up in a database. That database # contains a list of the user's preferred channels. # |
# If we don't find a cookie, we just give them some # default content. # # PLEASE NOTE: This is a script running under ActivePerl # on Win2k. Please change the first line to reflect # whatever system you're running Perl under. Please read # the legal message at the bottom. # |
# Prints out some standard HTTP headers. |
print header(-'Cache-Control'=>'private'); |
# Gets all the cookies and puts them into a hash. |
%cookies = fetch CGI::Cookie; |
if ($cookies{'moviereviewprefs'} ) { |
# If a cookie exists, we get its value (which is the
# user's ID number) and look up his preferences in a
# database.
#
# The preferences are pretty kludgy. We basically
# grab a list of six strings split apart by colons and
# stick them into an array. |
($propername, @prefs) = split(/~:~/,
$cookies{'moviereviewprefs'} -> value); |
} else { |
@prefs = (1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0);
$default = 1; |
} |
# Now, we print out the beginning of the Web page. |
print <<END_of_Start; |
<HTML>
<HEAD>
<TITLE>Movie reviews</title>
<META NAME="HandheldFriendly" content="True">
</head>
<body>
<Center><h2>The movie review channel!</h2></center>
<p>Version2.0</p> |
END_of_Start |
# print "<p>Your Id is $myID\n"; # print "<p>Your prefs is @prefs\n"; |
print "<p>Welcome, $propername </p>" unless $default;
print "<p>Here are a list of movies you might be interested
in...</p>\n <ul>\n"; |
dbmopen(%movies,"moviereviews",0644) || die "Can't open movieprefs! $!"; |
foreach $filmnumber (keys (%movies)) {
($filmname, @genres) = split(/~:~/, $movies{$filmnumber});
$match = 0;
for ($i =0; $i < 11; $i++) {
if ($genres[$i] && $prefs[$i]) {
$match = 1;
}
} |
if ($match) {
print "<li><A href=\"reviews/${filmnumber}.html\">$filmname</a>\n";
}
} |
dbmclose(%movies); |
print "</ul>\n<p>Tune in next time for more movie reviews!<p>\n"; |
if ($default) { |
# Informative message telling them to personalize their content
print "<center>Want personalized content? Of course you do!\n";
print "<br><a href=\"/cgi-bin/movies3/editprefsform.pl\">
Edit your preferences</a></center>\n"; |
} else { |
# They've already personalized, so we can be a little
# more understated here.
print "<a href=\"/cgi-bin/movies3/editprefsform.pl\">
Edit preferences</a>\n"; |
} |
print "</body>\n</html>\n"; |
# And now, the important legal message... # # Copyright (c) 2007, iAnywhere Solutions, Inc., # all rights reserved. # # IANYWHERE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT # THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR # PURPOSE, OR NON-INFRINGEMENT. IANYWHERE SHALL NOT BE # LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT # OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR # ITS DERIVATIVES. |
| Send feedback about this page using email. | Copyright © 2008, iAnywhere Solutions, Inc. |