.

Web Programming in C++p


Web Programming Course Help

What is CGI?

The common gateway interface is a set of standards which defines how the data may interchange between custom sprit and web server such as HTTP servers. This specs currently maintains NCSA.

Web Browsing


Web Programming in C++ Assignment Help By Online Tutoring and Guided Sessions from assignmenthippo.com


The browser contacts the HTTP server which demands for the filename. Web server will parse the filename and find the web server that sends the file back to the browser and sends a error message indicating the wrong requested file. Web browser always takes the response from the server to display the received file or error message sent back to the file.

CGI Architecture Diagram

web programming img1

Web Server Configuration

CGI is configured to handle the CGI program. All the programs are to be executed by the HTTP server should be kept in pre configured directory. CGI files will have the extension of .cgi.

Example

HTTP Header

The line content-type : text/html\r\n\n is the part of header file with HTTP header that is sent to the browser to understand the content.

Syntax

HTTP field name : Field Content

content-type : text/html\r\n\n

  1. Content-type: It is a MIME string which defines the format of the file being returned.
  2. Expires: Date: It defines the date the information of the current web page becomes invalid.
  3. Location: URL: The URL that has to be returned instead of the URL that is requested.
  4. Last-modified: Date: The date of last modification of the resource.
  5. Content-length: N: The length, in bytes, of the data being returned. This value 'N' is used by the browser to report the estimated download time.
  6. Set-Cookie: String: Used to set the cookie passed through the string

CGI Environmental Variables

  1. CONTENT_LENGTH: Optionally provides the length, in bytes. it's available only for POST requests.
  2. CONTENT_TYPE: Optionally provides the type of content i.e. the data type of the content.
  3. HTTP_COOKIE: Return the visitor's cookies, if one is set in the form of key & value pair.
  4. HTTP_USER_AGENT: The browser type of the visitor. It request-header field contains information about the user agent originating the request.
  5. PATH_INFO: It gives the path for the CGI script.
  6. REMOTE_ADDR: The IP address of the visitor, i.e. the IP address of the remote host making the request.
  7. REMOTE_HOST: The hostname of the visitor, i.e. the fully qualified name of the host making the request

C++ CGI Library

Many operations need to be performed to write CGI program. The CGI library written for the program that installs the library function to write the CGI program.

GET and POST methods

There are many situation arises when there is some information from the browser is passes to the web server to write CGI program. There are two methods to pass the information to the server. They are GET method and POST method.

Using Cookies in CGI

HTTP protocols are a stateless protocol required for maintaining the session information among different pages to create the commercial websites. Maintaining the user session information across all the web pages is known. The server sends some data to the browser in form of cookie.

  • Expires − This shows date the cookie will expire.
  • If this is blank, the cookie will expire when the visitor quits the browser.

  • Domain − This shows domain name of your site.
  • Path − This shows path to the directory or web page that set the cookie.
  • This may be blank if you want to retrieve the cookie from any directory or page.

  • Secure − If this field contains the word "secure" then the cookie may only be retrieved with a secure server. If this field is blank, no such restriction exists.
  • Name = Value − Cookies are set and retrieved in the form of key and value pairs.
.