Creating Bulletin Boards
Creating a simple CGI message board
The HTML Templates
The Bulletin Board Script
Displaying the Message List
Displaying Messages
Adding New Messages
Adding Replies
Expiring Messages
The Complete Bulletin Board Script


[Previous] [Next]


The Bulletin Board Script


Now that you have the HTML templates for displaying both the message list and the messages, you need to create the bulletin board script. Your script has to display the message list, display messages and replies, and post messages and replies. To make your script file easy to read, you can create subroutines for each of these tasks. The subroutines for the bulletin board script are Display_Message_Lists, Display_Message, Add_New_Message, and Add_Reply. You develop the code for each of these subroutines in the sections that follow.

You also create a fifth subroutine, Expires, that deletes messages that have been posted for over a certain number of days. This subroutine handles the most time consuming administrative chore associated with your bulletin board: deleting old messages. If you place the code for deleting old messages in a separate subroutine, you can easily change your bulletin board script to either expire or not expire old messages simply by either calling or not calling the Expires subroutine. You learn how to do this in the section "The Complete Bulletin Board Script" later in this article. There you also discover how to set the number of days messages remain on your bulletin board.

Before writing the five subroutines for the bulletin board script, you should create the files and directories in which the message lists, messages, and replies will be stored. You need two subdirectories, message-lists and messages. (If your operating system restricts you to eight-character directory names, change the directory name message-lists to m-lists and change message-lists to m-lists for the value assigned to the $list_dir variable in Listing 8 in the section "The Complete Bulletin Board Script.")

The message-lists directory will hold all the list files. For this example, list files store the headers for a single message and all the replies to that message. There can be numerous list files. The header information for each line in the list file will be in the form

 name::message subject::date message was posted::file name of message file


The message-lists directory also contains the count.dat file. This file stores a number that represents the name of the last list file that was created. For example, when a user posts the first message to your bulletin board, the list file containing the header for that message is named 1 and the count.dat file contains the single digit 1. The headers for all the replies to that first message is appended to the 1 file. When the second message is posted to your bulletin board, the header for that message is placed in the list file 2, and the value in the count.dat file is incremented to 2.

The messages directory is where you place all the text files containing the entire posting for both messages and replies. The files in this directory are also named with digits, such as 1, 2 and 3, and another count.dat file in this directory keeps track of the last file name used in this directory. There is no distinction between message files and reply files in the messages directory. This distinction is made by the configuration of the list files. The header information for the first entry in a list file always refers to the main message for that group. All other lines in the list file contain header information that refer to replies.

With the directories and the two count.dat files created, you can now begin writing the subroutines for your bulletin board script. You start with the Display_Message_Lists subroutine, which is called whenever a user wants to see the header lines for all the messages that have been posted in your bulletin board.


[Previous] [Next]