A web site interface preference tutorial
| From: | Colin Kettenacker | Date: | Mon, 20 Oct 2003 18:06:28 +0000 |
| Subject: | A web site interface preference tutorial | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-166790@lists.php.net to get a copy of this message | ||
Hey gang,
A couple of years ago (back when I first started to learn PHP) I came up
with some code that allows users to choose a interface style and color when
viewing a web site. I want to post the code as a tutorial for others because
I was never able to find a good resource on the subject.
To see it in action you can visit my woefully antiquated and never completed
site at <http://kettenacker.com/home/webprefs/> (I am
currently building my
company's new site where I will eventually post this tutorial in my resource
section).
Anyway I am interested in hearing any feedback/improvements/optimization
tips on this section of the code (This code checks if the user has chosen a
style and color preference for viewing the web site, if not, it will set it
to a default style and color preference):
---------------------------------------------
// Please feel free to use and abuse this code as you wish.
// If you find it at all useful perhaps you may wish to add the
// following credit to your code (but you are not obliged to):
// Original code provided by Colin Kettenacker <http://www.cube-o.com/>
// Code modified by (Add your name here if you have modified this code)
session_start();
// If the session variable 'prefAa' has been assigned then...
if (isset($_SESSION['prefsAa'])) {
// Extract the interface style and color information from it
$intStyleS = $_SESSION['prefsAa']['style'];
$intColorS = $_SESSION['prefsAa']['color'];
// If the session variable 'prefAa' has *not* been assigned yet then...
} else {
// If there are cookies present on the client's machine with
// the website's preference information then...
if (isset($_COOKIE['prefsAa'])) {
// Extract the interface style and color information from it
$intStyleS = $_COOKIE['prefsAa']['style'];
$intColorS = $_COOKIE['prefsAa']['color'];
// If there is *not* a cookie present on the client's machine with
// the website's preference information then...
} else {
// Set up a default interface style and color
$intStyleS = 'l'; // 'c' for (c)lean, 'l' for (l)ines
$intColorS = 'y'; // 'y' for gre(y), 'n' for gree(n),
'e' for blu(e)
// Attempt to create 2 cookies with the default interface style and
// color information
setcookie('prefsAa[style]', $intStyleS, time()+3600*24*7*52*10,
'/');
setcookie('prefsAa[color]', $intColorS, time()+3600*24*7*52*10,
'/');
} // end if
// Set the session variable 'prefAa'
$prefsAa = array( 'style' => $intStyleS,
'color' => $intColorS
);
$_SESSION['prefsAa'] = $prefsAa;
} // end if
---------------------------------------------
Any feedback/tips/hints/improvements to the code is appreciated. I will
hopefully have my company web site <http://www.cube-o.com/> finished within
the next month (Nov) with the full tutorial on it.
TIA,
ck
--
Cheap Domain Registration | Web Hosting | Email Packages | + more
Fantastic prices -- Even better service.
http://www.hosttohost.net