Server Side Scripting

Wikipedia The New Boston: PHP PHP
Wikipedia:PHP W3 Schools: PHP Wikipedia:ASP
Rails for Zombies Ruby Tutorial Wikipedia:Ruby
     

Common Gateway Interface (CGI)

CGI: RFC 3875

The CGI interface delegates the generation of web pages to executable files - this is in place of the simpler GET or POST methods for requesting web pages from a server. The files are known as CGI scripts and are written in a scripting language such as PHP, Perl or any language that produces a compiled executable program.

A web server that supports CGI can interpret a URL as a reference to CGI scripts. One convention is to have a cgi-bin folder in the root folder of a web site and to put all cgi scripts inside it.

Data are passed into a CGI program via standard environmental variables e.g. SERVER_SOFTWARE, SERVER_NAME, GATEWAY_INTERFACE.

Calling a command usually means that a new process is invoked - a program that is executed. This can take more time and memory than generating the output, especially if the program has to be interpreted or compiled before it is run. Compiled programs run faster but they are less easy to check for what they actually do than interpreted programs.

GET and POST Requests

A web browser uses HTTP to fetch web pages from a server. The server listens on port 80 for requests for pages. CGI is a web server extension that allows for the execution of programs, typically interpreted scripts. It is then the web server extension that generates the HTML to meet the request for the page. The CGI is a gateway between the web server and a web server extension: it tells the server how to send information to a web server extension and what the server should do in response. In simple terms, the gateway consists of a request object and a response object.

A web browser (HTTP client) opens a connection and sends a request message to a server. This will include an initial line with either a Get or a Post request.

Get uses a query string with a ? to add parameters for the requested page; each parameter has a value and these make up the name-value pairs that can be sent as part of GET. Multiple parameters are separated by &. Get is limited to a length of 2048 bytes minus the number of bytes for the URL address.

Post moves the name-value pairs of the query string into the message body. The Post method can send more data then Get.

Server Side Scripting

A web server extension can add the name-value pair information to a web page: this will be dynamic content because the value was not part of the original web page. This could be used to display information retrieved froma database. For example:

http://www.amazon.co.uk/s/ref=nb_sb_noss_1?url=search-alias%3Ddvd&field-keywords=breaking+bad

This is a request sent to Amazon for Film and TV and 'Breaking Bad' using the Get method. The values in the search terms are displayed at the top of the page that the server returns e.g. "Film & TV > breaking bad", followed by the data that Amazon retrieves from its database. You can see this by changing the case of the search term.

http://www.amazon.co.uk/s/ref=nb_sb_noss_1?url=search-alias%3Dpopular&field-keywords=keith+jarrett

This is a similar request for music by Keith Jarrett.

The pages returned are dynamic in the sense that the static HTML is a template for display of the data that were retrieved from the Amazon database.

Scripts may be simple or complex. The scripting language has commands to send data to the host that requested it and display e.g. Response.Write or echo.

The full content of a web page with dynamic content is not determined until the request is received. The server then retrieves the information and returns the page with the information contained within HTML.

Any values sent to the web server in Get and Post are passed to the web server extension. The script can recover the values from the request object and assign them to variables, which can then be embedded in the returned HTML by the web server extension. The extension writes the value into the variable of the Response object.

Post is used with a form. The form is used to collect data with names assigned through the controls on the form. When the Submit button is clicked the data in the controls are sent to the address embedded in the action part of the form header.

Get could be used with a hyperlink by including the data in name-value pairs, as shown above. Get can also be used in a form, in which case the name-value pairs are displayed in the URL as a query string.

Server Side Scripting Languages

PHP

Database Access

Access and ODBC using ASP

More ODBC and ASP