Download
slide1 n.
Skip this Video
Loading SlideShow in 5 Seconds..
CGI & HTML forms PowerPoint Presentation
Download Presentation
CGI & HTML forms

CGI & HTML forms

85 Views Download Presentation
Download Presentation

CGI & HTML forms

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. CGI & HTML forms -05-

  2. CGI Common Gateway Interface • A web server is only a pipe between user-agents • and content – it does not generate content

  3. CGI Common Gateway Interface • A web server is only a pipe between user-agents • and content – it does not generate content • Works well with static content (e.g. html files)

  4. CGI Common Gateway Interface • A web server is only a pipe between user-agents • and content – it does not generate content • Works well with static content, but what about • dynamic content?

  5. CGI Common Gateway Interface • A web server is only a pipe between user-agents • and content – it does not generate content • Works well with static content, but what about • dynamic content? • A web server needs to delegate content generation • to third party applications

  6. CGI Common Gateway Interface • A web server is only a pipe between user-agents • and content – it does not generate content • Works well with static content, but what about • dynamic content? • A web server needs to delegate content generation • to third party applications • Common Gateway Interface is a standard protocol • which defines how to delegate content generation • from a web server to a console application

  7. CGI Common Gateway Interface • If dynamic content generation is required, the web • server invokes console applications as commands

  8. CGI Common Gateway Interface • If dynamic content generation is required, the web • server invokes console applications as commands These console applications are often called CGI scripts Although they can be written in any programming language, scripting languages are often used

  9. CGI Common Gateway Interface • If dynamic content generation is required, the web • server invokes console applications as commands These console applications are often called CGI scripts Although they can be written in any programming language, scripting languages are often used • For example: wikipedia User makes a requests for an entry The web server activates a script which transforms the source of the entry into an HTML document and sends the result to the user

  10. CGI Common Gateway Interface • How do you tell a server to invoke an application • rather than send back its source code/binary form?

  11. CGI Common Gateway Interface • How do you tell a server to invoke an application • rather than send back its source code/binary form? The CGI scripts are placed in a special directory recognized by the web server

  12. CGI Common Gateway Interface • How do you tell a server to invoke an application • rather than send back its source code/binary form? The CGI scripts are placed in a special directory recognized by the web server Once there is a request for a resource in that directory, the web server knows to invoke the script/executable rather than return its content

  13. CGI Common Gateway Interface • How do you tell a server to invoke an application • rather than send back its source code/binary form? The CGI scripts are placed in a special directory recognized by the web server Once there is a request for a resource in that directory, the web server knows to invoke the script/executable rather than return its content Usually the directory is called cgi-bin under the web server’s path

  14. CGI Common Gateway Interface • How do you tell a server to invoke an application • rather than send back its source code/binary form? The CGI scripts are placed in a special directory recognized by the web server Once there is a request for a resource in that directory, the web server knows to invoke the script/executable rather than return its content Usually the directory is called cgi-bin under the web server’s path For security reasons only webmasters can update this directory or make it active

  15. CGI CGI specification

  16. CGI CGI specification • CGI defines how information about the request • (e.g. search query) is passed to the command

  17. CGI CGI specification • CGI defines how information about the request • (e.g. search query) is passed to the command The web server sets the environment variables with proper information

  18. CGI CGI specification • CGI defines how information about the request • (e.g. search query) is passed to the command The web server sets the environment variables with proper information If there is additional content (e.g. a PUT method), then it is passed using stdin

  19. CGI CGI specification • CGI defines how information about the request • (e.g. search query) is passed to the command The web server sets the environment variables with proper information If there is additional content (e.g. a PUT method), then it is passed using stdin • CGI sets rules for the CGI script output and how • it needs to be handled by the web server

  20. CGI CGI specification • CGI defines how information about the request • (e.g. search query) is passed to the command The web server sets the environment variables with proper information If there is additional content (e.g. a PUT method), then it is passed using stdin • CGI sets rules for the CGI script output and how • it needs to be handled by the web server The response is written to stdout

  21. CGI CGI specification • CGI defines how information about the request • (e.g. search query) is passed to the command The web server sets the environment variables with proper information If there is additional content (e.g. a PUT method), then it is passed using stdin • CGI sets rules for the CGI script output and how • it needs to be handled by the web server The response is written to stdout There are two types of response: NPH and CGI

  22. CGI CGI mechanism

  23. CGI CGI mechanism • CGI Script execution The web server acts like an application gateway

  24. CGI CGI mechanism • CGI Script execution The web server acts like an application gateway as follows: • Receives the request from a client

  25. CGI CGI mechanism • CGI Script execution The web server acts like an application gateway as follows: • Receives the request from a client • Selects a CGI script to handle the request

  26. CGI CGI mechanism • CGI Script execution The web server acts like an application gateway as follows: • Receives the request from a client • Selects a CGI script to handle the request • Converts the client’s request to a CGI request and sets the environment variables

  27. CGI CGI mechanism • CGI Script execution The web server acts like an application gateway as follows: • Receives the request from a client • Selects a CGI script to handle the request • Converts the client’s request to a CGI request and sets the environment variables • Executes the script (request data might not be immediately available through stdin)

  28. CGI CGI mechanism • CGI Script execution The web server acts like an application gateway as follows: • Receives the request from a client • Selects a CGI script to handle the request • Converts the client’s request to a CGI request and sets the environment variables • Executes the script (request data might not be immediately available through stdin) • Converts the CGI response into a response to the client

  29. Request CGI Request Response CGI Response CGI CGI mechanism • CGI Script execution The web server acts like an application gateway User CGI script Web server

  30. CGI CGI mechanism • CGI Script execution The web server acts like an application gateway The web server MAY act in a “non-transparent” manner, modifying the request or response in order to provide some additional service (e.g. media type transformation or protocol reduction)

  31. CGI CGI mechanism • CGI Script execution The web server acts like an application gateway The web server MAY act in a “non-transparent” manner, modifying the request or response in order to provide some additional service (e.g. media type transformation or protocol reduction) The web server has to conform to the client’s request protocol, even if the CGI script fails to

  32. CGI CGI mechanism • CGI Script execution The web server acts like an application gateway The web server MAY act in a “non-transparent” manner, modifying the request or response in order to provide some additional service (e.g. media type transformation or protocol reduction) The web server has to conform to the client’s request protocol, even if the CGI script fails to If authentication is involved, the script can be invoked only if access is granted

  33. CGI CGI mechanism • CGI Script selection

  34. CGI CGI mechanism • CGI Script selection The CGI script is selected based on the request URI

  35. CGI CGI mechanism • CGI Script selection The CGI script is selected based on the request URI The script may match the whole or a leading part of the hierarchical part

  36. CGI CGI mechanism • CGI Script selection The CGI script is selected based on the request URI The script may match the whole or a leading part of the hierarchical part The remainder of the path, if any, is a resource or sub-resource identifier to be interpreted by the script

  37. CGI CGI mechanism • CGI Script selection The CGI script is selected based on the request URI The script may match the whole or a leading part of the hierarchical part The remainder of the path, if any, is a resource or sub-resource identifier to be interpreted by the script Several paths may be associated with the same script

  38. CGI CGI Request

  39. CGI CGI Request • Meta-variables passed as environment variables The variables contain data about the request passed from the server to the script

  40. CGI CGI Request • Meta-variables passed as environment variables The variables contain data about the request passed from the server to the script They are identified by case-insensitive names; there cannot be two different variables whose names differ in case only

  41. CGI CGI Request • Meta-variables passed as environment variables The variables contain data about the request passed from the server to the script They are identified by case-insensitive names; there cannot be two different variables whose names differ in case only Usually they appear as capitals with underscores (e.g. PATH_INFO)

  42. CGI CGI Request • Meta-variables passed as environment variables The variables contain data about the request passed from the server to the script They are identified by case-insensitive names; there cannot be two different variables whose names differ in case only Usually they appear as capitals with underscores (e.g. PATH_INFO) A missing environment variable is equivalent to a zero-length (NULL) value; it is impossible to tell if the value is NULL or missing

  43. CGI CGI Request • Meta-variables passed as environment variables Some variables are set for every request, some don’t

  44. CGI CGI Request • Meta-variables passed as environment variables Some variables are set for every request, some don’t Variables set for every request

  45. CGI CGI Request • Meta-variables passed as environment variables Some variables are set for every request, some don’t Variables set for every request SERVER_SOFTWAREThe name and version of the web server SERVER_NAMEThe server's hostname or IP address GATEWAY_INTERFACEThe revision of the CGI specification to which this server complies (e.g. CGI/1.1)

  46. CGI CGI Request • Meta-variables passed as environment variables Some variables are set for every request, some don’t Request specific variables

  47. CGI CGI Request • Meta-variables passed as environment variables Some variables are set for every request, some don’t Request specific variables SERVER_PROTOCOLThe name and revision of the protocol this request came in with (e.g. HTTP/1.1) SERVER_PORTThe port number to which the request was sent REQUEST_METHODThe method with which the request was made (e.g. POST)

  48. CGI CGI Request • Meta-variables passed as environment variables Some variables are set for every request, some don’t Request specific variables REMOTE_ADDRThe IP address of the client REMOTE_HOSTThe hostname of the client the request

  49. CGI CGI Request • Meta-variables passed as environment variables Some variables are set for every request, some don’t Request specific variables PATH_INFOIdentifies the resource or sub-resource derived from the portion of the URI path hierarchy following the part that identifies the script itself PATH_TRANSLATEDThe server provides a translated version of PATH_INFO, which takes the path and does any virtual-to-physical mapping to it

  50. CGI CGI Request • Meta-variables passed as environment variables Some variables are set for every request, some don’t Request specific variables QUERY_STRINGThe part of the request URI which follows the first ? This string is added either by an HTML form with a GET method or by an HTML anchor This string is encoded in the standard URL format – spaces are replaced by “+” and special characters are encoded with %xx (hex value)for example: “ur/ a%&”  “ur%2F+a%25%26”