- Shopping Bag ( 0 items )
If you want to make your Web site as interactive as possible, as soon as possible, you've come to the right ...
Ships from: Fort Worth, TX
Usually ships in 1-2 business days
Ships from: River Hills, WI
Usually ships in 1-2 business days
Ships from: acton, MA
Usually ships in 1-2 business days
If you want to make your Web site as interactive as possible, as soon as possible, you've come to the right place! This book/CD powerhouse arms you with 20 of today's most-demanded CGI programs and subroutines, designed and written especially for this book, each ready to load and use. At the same time, it offers you a quick, painless, and unique hands-on way to learn basic and advanced CGI/Perl programming.
The CGI/Perl Cookbook begins with a concise overview of CGI programming for beginners, followed by a guide to installing CGI programs on UNIX, PC, and MacOS Web servers. The rest of the book is devoted to line-by-line, feature-by-feature explanations of seven cutting-edge CGI programs; including a search engine, password protection, advanced form processing, a shopping cart, customized bulk e-mail, advanced visitor feedback, and more; as well as 13 subroutines for e-mail support, file encoding, credit card validation, e-mail address checking, error handling, and text encryption. You also get a usage guide, installation instructions, and professional CGI and Perl programming tricks and customization tips for each program and subroutine.
The CD-ROM is a gold mine of ready-to-use software and valuable information. You get:
* All the CGI programs from the book-code and ready-to-run versions
* The complete Matt's Script Archive
* A collection of the best scripts from across the Web-source code included
* The complete Perl programming manual
* The most recent Windows, UNIX, and MacOS versions of Perl
The programs and subroutines written for this book are provided in a ready-to-run format that, in most cases, only require you to modify a few configuration variables before they'll work on your server. You do need to install them first, however, and while each program chapter includes its own section covering installation details specific to that particular program, there are some general procedures that apply to them all. This chapter will go over those procedures with you and walk you through the process of installing a generic CGI program on your server. If you're already familiar with this process, then you can skip this chapter and go right to the first program in Chapter 4 (or to whichever program interests you most).
Many people who haven't used CGI programs before (or who have used programs that were installed by someone else) seem to have the misconception that installing one requires some kind of technical degree. This probably originated with early CGI programmers who wanted to protect their consulting income by making the whole process seem a lot more complicated than it really is. The truth is that installing a CGI program requires three simple steps, regardless of what operating system and Web server you're using:
2. Move the program into the appropriate directory.
3. Make sure your server knows about and can access the program.
That's pretty much all there is to it. The programs in this book also depend on some required support files that need to be copied to the server, but the process for doing so uses these same three steps. Since the exact implementation of these steps varies from platform to platform, we've included specific instructions for Unix, Windows, and MacOS servers.
Because we have a limited number of pages to fill and a lot of information to pack into them, we have had to make a few basic assumptions for this chapter regarding your familiarity with your Web server. If any of these assumptions don't hold true for you, then you can rectify the situation by asking your ISP's system administrator a few questions or by consulting your server's documentation if you're running your own server.
You Have Access to a Web Server
This may sound like an obvious assumption, but some people don't realize that you cannot run a CGI program unless it is installed on a Web server. This means that either you have an account with an Internet Service Provider (ISP) that allows you to install Web pages and CGI programs on their server, or that you own or have access to a computer that is connected to the Internet and running Web server software. (Craig used CTSNet at www.cts.com during the development of the book and Matt used World Wide Mart at www.worldwidemart.com. All of the code has been tested on their servers already, so if you need to find an ISP we highly recommend both.)
For debugging purposes it is also helpful (although not required) if you have telnet access to a shell account on your server. This allows you to test the programs on the server itself rather than testing them on your local computer. If you're not sure whether or not you have telnet access, check with your ISP.
Perl Is Installed on Your Server
Although we have provided copies of Perl for a variety of platforms on the accompanying CD-ROM, it is beyond the scope of this book to cover the installation process. We will therefore assume that you are either using a server that already has Perl installed or that you are capable of installing Perl yourself from the CD-ROM (Readme files should be included with each version that explain the process.) If you're using a Unix-based server, then we also assume that you know where the Perl executable is located on your server. You can find out by checking with your system administrator or by using one of the following commands from the Unix shell prompt (some servers may not support these commands):
where is perl
You Have Access to a CGI Directory
Depending on the type of server you're using, the platform it is running on, and the way it has been configured, CGI programs may need to reside in a special directory in order to run. (Some servers allow you to keep CGI programs anywhere on the server's Web space as long as the filename ends with . cgi.) Traditionally this directory is named cgi-bin (especially on Unix servers), but it can have any name as long as the server is configured to recognize it. The process for doing so varies from server to server but in all cases must be performed by the system administrator. If you are using an ISP for your Web account, then you will need to ask the system administrator where to install your CGI programs. Otherwise please refer to your server software's documentation for instructions on how to configure a directory for CGI access.
NOTE: You cannot simply create a directory named cgi-bin, place a CGI program in it, and expect it to run. Your server must be configured by the system administrator to recognize a directory before it can be used for CGI access.
You Know How to Transfer Files to Your Web Server
Unless you have access to your Web server through your computer's file system, you will most likely need to transfer the programs in this book from the accompanying CD-ROM (or our Web site) to your server using an FTP program. We assume that you already know how to do this and have probably done so with HTML pages in the past. If not, you will need to get instructions from your ISP on how to go about it. (It's easy.)
On the CD-ROM, you'll notice that we provide Unix, Windows, and MacOS versions of each program and their supporting files. These versions differ only in the characters used to terminate each line in the file. (Each platform is different.) If you are transferring files directly from the CD-ROM, then make sure you transfer them from the directory that corresponds to the platform your server is running on. If you open and save these files on a different platform than the one your server is running on (i.e., your server is on a Unix machine and your home computer is a Mac), make sure you edit the version for your server's platform and that your editing program doesn't change the line breaks when it saves the file. You should also make sure that when you transfer the files to your server, you do so in ASCII mode as opposed to binary mode. (See the instructions for your FTP program if you're not sure how to do this.) In many cases this will take care of any line break problems.
Thanks to the standardized CGI protocol, the difference in the way CGI programs are installed on different platforms is small, as you will see in the following summaries.
Installing a CGI program on a Unix-based server is a little more involved than on other platforms, but it is still a relatively straightforward process. Once the program has been copied into the appropriate directory, the only remaining step is to make sure that the program file has the correct access permissions (these dictate who can read from, write to, or execute the file).
Setting File Permissions
File permissions are set using Unix's chmod, command, the format for which is as follows:
chmod permissions filename
permissions is a three-digit number that indicates the type of permissions to give to the file. This number confuses a lot of people who aren't used to Unix, but it is actually very easy to understand once you know what it means.
The first digit defines what permissions the owner of the file has (i.e., the person who created the file), the second dictates what permissions the group that the owner belongs to has, and the third dictates what permissions everyone else has. Each category of permission (read, write, execute) is assigned a numeric value. Read permission is 4, write permission is 2, and execute permission is 1 (execute permission for a directory means that the directory can be searched). If you want the owner of the file to have permission to read, write, and execute the file, then you use a 7 (4 + 2 + 1) for the second digit. If you want the group to have permission to read and execute only, then you use a 5 (4 + 1) for the third digit. An example chmod command that gave full permissions to the owner and read and execute permissions to the group and everyone else would look like this:
chmod 755 filename
Typically these (7 5 5) are the permissions settings you will want to give to your CGI programs. (Required, template, and data files don't need to be executable, so you will use 644 with them.) You may also want to create an empty index.html file in the same directory as you CGI programs and set its permissions to 7 00. This will prevent people from getting access to your programs by using the URL of your CGI directory.
NOTE: Don't forget to set the access permissions for any directories or subdirectories you create when setting up your program. Otherwise you will not be able access your files properly, even if their permissions are set correctly.
Running the Program
Once your program is in the right directory with the file permissions set properly, it should be all set to run. You can test it by entering the URL of the directory it is saved in (check with your system administrator if you don't know what this URL is), followed by the name of the program file, into your browser.
The installation process for Windows-based servers is the simplest of the three. The process of installing the Windows version of Perl automatically associates the cgi and pl extensions with the application, so your programs will be executable as soon as they are copied to your server's hard drive. The only extra step you need to worry about is copying them into a directory that is accessible by the server. If you are not sure what directories this includes, you should check with your system administrator. Once the program is in a valid directory, you can run it by opening the URL in our browser
The installation process for MacOS-based servers is also very straightforward. just follow these steps for each CGI program you want to install (required files can simply be copied to the appropriate directory):
2. Select Save As... from the File menu.
3. Select CGI Script from the popup, menu at the bottom of the Save dialog box.
4. Name and save the file.
This procedure will create an executable file that can be called the same as any other CGI program. At this point you can test the program by entering its URL into your browser's location input area.
NOTE: If you have an older version of MacPerl and don't see CGI Script as a choice in step 3, you will need to either update the version you're using or download the PCGI package from ftp:// err.ethz.ch/pub/neeri/macperi and copy the file CGI Script into the MacPerl Extensions folder in the MacPerl folder.
"403 Forbidden" Error
This message indicates that the file permissions for the program are probably set incorrectly. Remember to set the permissions for the directory and/or subdirectory your program file is in as well as for the program file itself.
"404 Not Found" Error
If you get this message after attempting to access a program, then you've probably entered an invalid URL for the program. Double check the URL you're using and make sure you have specified the correct name and location of the program file. (Remember that uppercase letters are different than lowercase letters to Unix.)
"500 Server Error" Error
This error indicates that the program is not producing output that the server understands and generally indicates a problem with the program itself. You can check your server's error log for a more detailed explanation of the problem (check with your system administrator to find out where the error log is kept). If you get this error with one of the programs in this book, then there is probably a problem with one of the configuration variables in the program. Double-check each variable to make sure you didn't accidentally omit a closing quote or semicolon at the end of the line. Then try some of the debugging techniques presented in Appendix A to see if you can locate the problem. If not, please check the book's Web site to see if anyone else has had the same problem and/or let us know about the problem by filling in the bug report at the book's Web site (www.wiley.com/compbooks/cgi-perl). We'll do our best to take care of it as quickly as possible.
Using This Book.
Using CGI and Perl.
Installing CGI Programs.
Managing Files: Fileseek.CGI.
Gathering Input: Formhandler.CGI.
Spreading the Word: Broadcaster.CGI.
Doing Business: Webshop.CGI.
Getting Opinions: Feedback.CGI.
Keeping Track: Pagecontrol.CGI.
Restricting Access: Authenticate.CGI.
Getting Support: The Subroutines.
Posted May 16, 2000
An excellent resource for learning CGI scripting. It covers such full-featured CGI applications as advanced form handling, authentication, file search, user feedback, shopping cart and more. Also included is a library of 13 utility subroutines that include email for any platform, date formatting, template parsing, and much more. All scripts and subroutines are ready to use and include line-by-line explanations of their code.Was this review helpful? Yes NoThank you for your feedback. Report this reviewThank you, this review has been flagged.