This is a litte collection of PHP functions to manage a "Message of the Day" feature in a dynamic web page.
It can be useful to implement a UNIX fortune-like welcome message on a web site, but it can also integrated to produce random e-mail signature. The message file, from which the system picks up a random item (called fortune cookie or simply cookie), has the standard format of UNIX fortune file.
There is also available a collection of English fortune cookies to use as a sample database. I have collected these quotes from many sources freely accessible on the Web, since I suppose that they are of Public Domain and freely distributable. If you find copyrighted any material, please notice it to me.
This software is released under GNU General Public License. It can be freely used, modified and distributed in conformity with the GNU General Public License. The License Agreement is available here. For any information about the GNU GPL and its implications please refer to GNU site. The License Agreement is provided in the source file.
Notice that cookie collection is provided as Public Domain material.
In order to use this software you need a PHP 4 compatible web server. A PHP module can be downloaded PHP site and it can easily integrated with Apache Web Server. To use PHP with another web server please refer to their own documentation.
The library source file is available here, and the sample cookie database is here.
These instructions are assuming that a PHP interpreter is installed and correctly configured and the source file has been downloaded.
The message database is an ASCII text file containing a list of "fortune cookies".
Each cookie is represented as set of lines and is delimited by lines starting with two %s.
This is an example of message file:
This is the 1st message %% This is the 2nd message (1st line) This is the 2nd message (2nd line) %%%%%%%%%%%%%%%%%%%%%%%%%%% Thi is the 3rd messageTo edit the message database you need a simple text editor.
Suppose that the database to be indexed is called cookie.txt. In order to
index this file the index cookie.ndx we write this simple PHP script:
<?php
require ('cookie.inc');
build_index ('cookie.txt', 'cookie.ndx');
?>
to be saved in the cookie.txt directory as build_index.php.
We put the file cookie.inc in the same place. The script can be executed with the
following command:
php < build_index.phpassuming the PHP script interpreter is correctly added to the
PATH
enviroment variable (see the PHP installation instructions and the operating
system documentation) and the current directory is the one containing the
database file and scripts.
If everything goes right a file cookie.ndx has been created.
Each PHP page that shows a message of the day have to require the file cookie.inc.
The directive depends on the location of the included file w.r.t. the location of
the page, assuming that they are located in the same directory, the following
PHP statement should be enough:
require ('coockie.inc');
It can be modified according to installation specific issues.
To print out a message of the day you need to use the function pick_a_cookie,
that takes two arguments:
This function builds a <QUOTE> element and delimits each
message line with a <BR> tag, it inserts required HTML entities
too. If you need to change this behavior you have to modify the function
accordingly.
To publish a cookied-application we need to upload on the web server the following elements: