SlideServe
Menu
Préférences
© SlideServe · v2026

Understanding CGI Programming with Apache: A Practical Guide

brent-ortega avatar
9 diapositives · 223 Views · Nov 17, 2014

This guide explores the concepts of Common Gateway Interface (CGI) programming using the Apache web server. It covers how browsers prepare parameter lists, send them to the server, and how the server processes these requests. Learn about generating HTML output with C++, handling content types, and addressing common problems. The tutorial also includes steps to set up an Apache server, create HTML forms, and integrate JavaScript for dynamic web pages. Perfect for beginners seeking to understand server-client interaction in web development.

Understanding CGI Programming with Apache: A Practical Guide - slide 1
01 / 9Understanding CGI Programming with Apache: A Practical Guide
1 / 17

Télécharger la présentation

Understanding CGI Programming with Apache: A Practical Guide
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. CGI programming Using Apache

  2. Concepts • Browser • prepares parameter list • List is attached to name of program to run on server • "submit" button sends string to server as name/value pairs • Server locates program in CGI directory • Server loads program • Server passes string to program • Program processes parameters and acts as needed • Program creates strings and outputs to server • One line of HTML code per output statement (cout, printf, etc) • ALL stream output goes to the Server • Server sends strings to browser • Browser interprets the HTML code & displays the "page"

  3. CGI output (C++ example) #include <iomanip> cout << "Content-Type: text/html\n\n" << endl; cout << "<!DOCTYPE html>" << endl; // HTML 5 cout << "<html>" << endl; …. Your HTML & text go here … cout << "</html>" << endl; • 1st line identifies output media type to browser • 2nd line identifies document type version • 3rd line is actual start of the page

  4. Content-type problems • Inability of data source to identify content • Wrong file extension • Bad file extension • Extension collisions • Ambiguous container formats • Ambiguous magic numbers • Inability of receiver to trust sender's media type • Programmers try to guess content type by examination

  5. Using styles • Output is a stream representing a single "file" • HTML files do NOT have to have one tag per line • Output can be individual lines or several long lines: cout<< "<p> text <ol><li>item1</li></ol>"<<endl; • Styles can be embedded or inline • Generate style tags just like any other HTML cout << "<style> .red {font:red} " << endl; cout << ".bigtext {text-size:150%} " << endl; </style>" << endl;

  6. Using JavaScript • JS can be inserted: • as functions in <head> </head> • As inline code inside <script></script> in body of doc • CGI generated pages "act like" real pages

  7. Activating your CGI program • Generate an HTML form (using cout or printf): <form name='myform' action="cgi-bin/your program's executable"method='post' > <!-- for testing: use action='mailto:your email address' --> … {your JS function def's and html and go here} document.myform.submit(); // this submits the form to the browser <td><input onclick='chkflds();' type='button' value="multiply them!"></TD> </form> • Where I have "chkflds" you could put the name of a function to validate the fields • The function would have to be inside <script> and <head> tags • RECOMMENDATION: put the form's elements inside a table • <form> <table> .. Input/button tags here… </table></form>

  8. Setting up your Apache server • Open terminal window • Type: nano /etc/httpd/conf/httpd.conf (or use your favorite editor instead of nano) • Locate "ServerAdmin" and replace the email address with yours • Locate "ServerName" and replace the default with your TJWnnn account (tjwnnn.cc.binghamton.edu) • Save the file using the same name it had • In the terminal window type the following command:apachectl start • Close your session

  9. Testing your web server • Create a simple web page • Save it in /var/www/html with the name: index.html • Open a browser on your own PC (NOT on the TJW machine) • Enter the address of your tjw accounte.g.; tjw241.cc.binghamton.edu (that's mine!!) • You should now see your test page