Unformatted text preview:

CGI Program HandoutFollow these direction carefully:1. Create the HTML, CGI and CPP files as outlined on the following pagesBe sure you have a LD_LIBRARY_PATH in your environment that has/usr/local/lib in it. If not, add the following to your .cshrc file :setenv LD_LIBRARY_PATH /usr/local/libThe HTML Document (simpleCGI.html)The DoIt.cgi Bourne Shell ScriptThe C++ CGI Program (cgiExample.cpp)CGI Program HandoutCS 400READ CAREFULLY and have fun. Be sure you spend enough time to understand how all the parts work together. Follow these direction carefully:Compile your C++ CGI as follows:% g++ -static-libgcc –static cgiExample.cpp –o cgiExample1. Create the HTML, CGI and CPP files as outlined on the following pagesPlace ALL files in the .public_html directory under your home directory. For example if your user name is joe, then create a .public_html under joe. 2. Then from joe type:% chmod 755 public_html3. Make access to the HTML and CGI file % chmod 755 *.html *.cgi4. Go to your browser and open the following page:http://www.bridgeport.edu/~ joe /simpleCGI.htmlYou will see the following page:5. Type in your name and ID6. Press OK, and the following result should occur7. The result in step 6 was the C++ CGI script sending data to your browser. A successful running of this example, and the understanding of how it works is the goal of this example.8. Please read through the C++ source code to see how the parameters were taken out of the input. If you look at step #6, you will see that the parameter string passed to the C++ program was in the following form:studentName=Alfonso&ID=456789The general form is param1=value1&param2=value2&param3=value3 …9 I use strstr() and strchr() string.h function to do most of the work. In your real assignment, you will have to pass input parameters, and return the records from the file in an HTML table.Be sure you have a LD_LIBRARY_PATH in your environment that has/usr/local/lib in it. If not, add the following to your .cshrc file :setenv LD_LIBRARY_PATH /usr/local/libThe HTML Document (simpleCGI.html)<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> New Document </TITLE><BODY BGCOLOR="008080"><META NAME="Generator" CONTENT="EditPlus"><META NAME="Author" CONTENT=""><META NAME="Keywords" CONTENT=""><META NAME="Description" CONTENT=""></HEAD><BODY><FORM METHOD=GET ACTION="DoIt.cgi"><INPUT TYPE="text" NAME="studentName"> Name (First and Last)<BR><INPUT TYPE="text" NAME="ID"> Valid UB ID Number<BR><INPUT TYPE="submit" VALUE="Ok"></FORM></BODY></HTML>The DoIt.cgi Bourne Shell Script#!/usr/bin/shecho Content/type: text/htmlecho# QUERY_STRING has the parameters you passed from the form./cgiExample "$QUERY_STRING"The C++ CGI Program (cgiExample.cpp)#include <iostream.h>#include <fstream.h>#include <stdlib.h>#include <string.h>int main(int argc, char * argv[]) {char id[10];char name[20];if(argc < 2) { cout << "You need to supply correct data values on form"; cout << "Error - Program exiting\n";exit(1); }cout << "Content-type: text/html";fstream file("datafile.dat", ios::out | ios::app);file.seekp(0L, ios::end);char * string1, * string2;string1 = strstr(argv[1], "ID");string2 = strstr(argv[1],"studentName");char * beg = strchr(string2, '=');beg++;char * end = strchr(beg, '&');int length = end - beg;strncpy(name,beg,length);beg = strchr(string1, '=');beg++;end = beg + strlen(string1); length = end - beg;strncpy(id,beg,length);if (string1) file << "ID: " << id ;else file << "VOID";file << "\t";if (string2) file << "Name: " << name << "\n";else file << "VOID";file << "\n";cout << "<H3>CGI Response To You</H3>";cout << "<TABLE BORDER=3>";cout << "<TR><TD>NAME</TD><TD>ID#</TD></TR>";cout << "<TR><TD>" << name << "</TD><TD>" << id << "</TD></TR></TABLE>"; return 0;


View Full Document

UB CS 400 - CGI Program Handout

Download CGI Program Handout
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CGI Program Handout and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CGI Program Handout 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?