Server-Side Scripting Languages - HTML

Several different scripting languages are available for use on Web servers—more are appearing each day. This section describes the most popular languages and technologies in use today.

Common Gateway Interface
The Common Gateway Interface (CGI) was developed as a standard way for programs to talk to a Web server, thereby extending the server’s capabilities. The CGI specification allows most programming languages to interact with Web servers. As long as a language can accomplish the following tasks, it is a viable CGI platform:

  • Read from standard input
  • Write to standard output
  • Read from environment variables

Tip:Just because a programming language can be used to implement CGI doesn’t mean that it should be used. There are several security concerns relating to using CGI with a Web server. Many of the more common CGI-capable languages have built-in security components and therefore are safer to use. Other, unproven languages (operating system, macro languages, and so on) can present the outside world with more access to your server and underlying file system than you intend.

The most common CGI languages are C and Perl. The former is a compiled language, that is, it needs to be converted to a binary program before it can be run. The latter is an interpreted language—interpreted languages are converted into binary programs on the fly, as they are run.

Note;Keep in mind that a program must output data in a form recognized by the user’s interface, typically a Web browser. For example, a CGI program used to render an HTML document must pass the correct MIME type and document type definition as well as encapsulate its output in appropriate HTML tags.

Each type of programming language (compiled/interpreted) has distinct advantages and disadvantages. Compiled languages tend to be faster executing, but require the extra compilation step to be deployed. Interpreted languages are a bit slower, but provide a little more flexibility during development.

Note;A great online resource for CGI scripting is the CGI Resource Index.

Several varieties of C are available for Windows and Linux platforms. Likewise, Perl is available for most platforms.

ASP, .NET, and Microsoft’s technologies
As with most technologies, Microsoft has made several noteworthy achievements in creating tools and deployment solutions for the Internet. The latest initiative, .NET (pronounced dot-net), provides a solid platform to develop and deploy solutions over the Internet using Microsoft technology.

Microsoft’s earliest contributions to the Web were in the form of Active Server Pages (ASP) and ActiveX controls. ASP is Microsoft’s answer to CGI, allowing their programming languages to be used to extend a Web server’s capabilities. ActiveX controls extended the interactivity possible in Web pages by providing standard, Windows-like controls for users to interact with data on the Web. An example of a complex ActiveX control is provided, which shows the interface for a popular network camera.

Note:ActiveX controls only loosely fit into the scheme of server-side scripting, because they are actually downloaded and used by the client instead of the server. They are mentioned here for a sense of completeness and because they provide a viable option for extending the capabilities of the Web.

For the most part, ASP operates much like standard CGI, incorporating programs to extend a server’s capabilities. For example, the following code uses Visual Basic to store a value that is later output within an HTML document:

This simple example only scratches the surface of the power behind ASP. More complex code could look up data in a database and present it in tabular format or perform other complex operations whose results could then be presented in HTML, using the same method as shown previously.

The ActiveX control used by a popular network camera to allow control of the camera over the Internet.

The ActiveX control used by a popular network camera to allow control of the camera over the Internet.

To use ASP (and the latest ASP.NET) requires a Microsoft Server running IIS along with the various pieces of ASP and .NET technologies. A good tutorial for getting up and running with ASP appears on the ASP101.com Web site, at www.asp101.com/lessons/install.asp.

PHP
PHP is a relative newcomer to the server-side scripting arena. However, it is one of the few solutions that were developed specifically for Web automation. As such, it has the most robust set of features for presenting all kinds of data in Web-friendly formats.

Hypertext Preprocessor (PHP for short) is essentially a general-purpose scripting language with the following features:

  • Based on open source technologies
  • The capability to run before the resulting page is displayed
  • A Perl-like structure and syntax
  • Robust HTTP handling capabilities
  • The capability to coexist with raw HTML in the same file
  • Modules for interacting with other technologies, such as MySQL

Unfortunately, PHP also has some serious drawbacks, also relating to its newness and genesis as a Web programming language:

  • Numerous security issues (although they are typically found and fixed quickly) are compounded by the relative accessibility of the language to fledgling programmers.
  • PHP versions up through 4.3 do not have robust object handling capabilities. As such, the language is not as flexible (or, arguably, as powerful) as those languages that do have robust object-oriented programming (OOP) structures.
  • The structure of PHP programs can be fairly loose, allowing bad programming techniques to be used where highly structured code would otherwise be used. (Note that this is also a benefit as PHP tends to be easy to learn and the concern is mitigated if the person learning PHP takes the time to learn good programming habits as well.)

The following code is an example of how PHP could be used to render the “Hello World” example shown in the ASP section, earlier in this chapter:

As with the earlier ASP example, this simple PHP example only scratches the surface of what you can accomplish with PHP. Instead of simply setting a string variable, the code could access a database and present the resulting data in a number of complex forms. PHP is available on Windows and Linux and requires that the PHP processor be installed on the Web server (both operating system and Web server application).

Note:You can find several sources of information online for PHP. The best resource, which has full language documentation, sample code, and more. For more sample code, visit the PHP Resource Index.

ColdFusion
ColdFusion by Allaire (now owned by Macromedia) is one product that greatly increases what your Web site can do without requiring any programming. Using a simple language, called Cold Fusion Markup Language(CFML), you can create powerful scripts you write right into your HTML pages. The ColdFusion server returns the script’s results right into your page.

Some of the cool things you can do are as follows:

  • Schedule the generation of a page daily, hourly, or at whatever interval you choose.
  • Pull content off other sites and parse it into your own format. (Get permission from the site owner before you try this.)
  • Send mail to everyone in a database from a Web page based on criteria indicated on the form on the Web page.
  • Insert records into a database. Update a database record. Read a database for records that meet certain criteria.
  • ColdFusion is available for both NT and UNIX (Solaris) platforms. It works with ODBC-compliant databases.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

HTML Topics