Helping ordinary people create extraordinary websites!
GET OUR NEWSLETTER
Your Email:
 

Build a Perl/CGI Voting System

By Allan Peda
2005-07-05


Details: File layout

Installation requires three types of directories on the Web server:
  • A writable directory for saving user submissions
  • An area for the CGI to run from
  • An area where static data (such as CSS, logo images, and possibly a file containing more detailed instructions) can reside

Also note that permissions will most likely need to be tweaked so that the Web server can write to the directory for the DBM files.

Listing 2 shows the creation of some typical directories on the Web server.

Listing 2. Setting up directories on the Web server



$ id uid=500(allan) gid=500(allan) groups=10(wheel),48(apache),500(allan)
$ sudo mkdir /var/www/db /var/www/javascript/ /var/www/css/
$ sudo chmod 2775 /var/www/db
$ sudo chmod 2755 /var/www/javascript/ /var/www/css/
$ sudo chown apache.apache /var/www/db/

Strictly speaking, only the cgi-bin (/var/www/cgi-bin) and DBM (/var/www/db) directories are absolutely essential, since they hold the script executable and the voting data, respectively. The layout shown in Listing 1 is specific to Linux, and the user and group names of the Web server process may vary, but the essential point is that there are several components that need to be placed in the correct area of the file system to be available to the Web server. After copying the support files into their respective directories, be sure to update any aliases in the Web server configuration files such as httpd.conf.

After creating the directories as described in Listing 2, copy the files from the ZIP file into the analogous subdirectories on your system. Most importantly, the ballot, DraftBallot.pm, BallotBox.pm, and CastBallot.pm files should be in the cgi-bin directory. Only three nonstandard Perl modules are required; the process of installing them is presented in Listing 3 (see the modules' README files for more details).

Listing 3. Installation of Perl modules



$ sudo perl -MCPAN -e 'install MLDBM'
$ sudo perl -MCPAN -e 'install MLDBM::Sync'
$ sudo perl -MCPAN -e 'install MIME::Lite'


Tutorial Pages:
» Using locked DBM files with CGI-driven forms saves client data without DBMS overkill
» CGI considerations: Simplicity vs. complexity
» Functional design considerations
» Details: Hash keys
» Details: E-mail gotchas
» Details: Not-so-secret ballots
» Details: File layout
» Details: Static vs. dynamic DNS
» Details: Is GET harmful?
» Other possible improvements
» Conclusion
» Resources


First published by IBM DeveloperWorks


 | Bookmark
Related Tutorials:
» Random subroutines in Perl
» Log Script Use
» Creating Perl Modules for Web Sites
» Bit Vector, Using Perl Vec
» Perl Range Operator
» Creating Perl Modules for Websites

Advertise with Us!


Tutorials Scripts Web Hosting Developer Manuals
Resources