What are scripting languages?
Scripting languages are specialised programming languages that produce scripts, and have their origins in the Job Control Language (JCL), a scripting language used on IBM mainframe operating systems to tell the system how to run a batch job or start a subsystem. They are also related to the batch files used to sequentially execute a group of system commands under DOS and Windows. Scripts are text files that contain program source code rather than executable binary files in their own right. When invoked, the source code is interpreted by an interpreter. Scripting languages offer a way of quickly and easily developing and deploying web applications, both on client computers (client-side scripting) and on servers (server-side scripting), at the cost of runtime efficiency (interpreted programs tend to run significantly slower than binary executable programs).
In the "traditional" approach to client-server transactions, Web servers pass client requests to server-side scripts and receive the results of script processing via the Common Gateway Interface (CGI). The response is usually a dynamically generated Web page containing information intended to satisfy the requirements of the original query (or specifying a reason why the request cannot be satisfied). One common use of server-side scripts is to update the information in a database or retrieve the results of a database query. Today, scripting environments such as Microsoft?s ASP, Sun Microsystem?s JSP, and the open source PHP allow the direct execution of scripts, enabling them to be run by the Web server independently of the Common Gateway Interface. This usually results in lower processing overhead, and consequently better performance. As of 2008, the most widely used server-side scripting language was PHP.
Active Server Pages
Microsoft's Active Server Pages (ASP) was one of the first Web application development environments to implement the direct execution of scripts, independently of the Common Gateway Interface. The scripts are embedded directly into HTML documents, which are given the extension .asp, and can contain any combination of HTML and scripting (e.g. VBScript, JScript etc.), as well as calls to components such as ActiveX controls. When a server receives a request for an ASP page, it will parse the contents of the .asp page in order to extract and process the ASP code embedded within it. ASP commands are enclosed between the delimiters <% and %>. After processing, the server will send the resulting web page (an HTML document) to the client. The example code below demonstrates how VBScript (the default scripting language) can be used with ASP to process a logon request.
<%@ LANGUAGE="VBSCRIPT" %>
<!-- FILE: login.asp -->
IF IsEmpty(Request.Form("Name")) THEN
Response.Write "Please enter your Name"
<FORM ACTION="login.asp" METHOD=POST>
<INPUT NAME="Name" TYPE=TEXTBOX MAXLENGTH=20>
<INPUT TYPE="SUBMIT" VALUE="Submit">
Response.Write "Welcome " & Request.Form("Name") & "!"
From version 2.0 of ASP.NET onwards, all controls generate valid HTML or XHTML output, the detection of standards-compliant web browsers has been made more reliable, and support for Cascading Style Sheets has been improved. Although primarily designed for use on servers running Microsoft Windows Server, .NET applications can also be ported to other platforms, including Linux, Unix, Mac OS X and Solaris, thanks to Mono, an open source .NET development framework sponsored by Novell.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
JavaServer Pages (JSP) is a Web application development environment developed by Sun Microsystems. As with Microsoft?s Active Server Pages, JSP script elements, including Java code and consisting of Java code and certain pre-defined actions, are embedded directly into HTML documents. The resulting JSP pages are given the file extension .jsp. When requested by a client, JSP pages are compiled into Java servlets by a JSP compiler. As with the Java programming language itself, the development of JavaServer Pages is subject to the Java Community Process (JCP).
Perl is a high-level, general purpose, interpreted programming language originally developed by Larry Wall, a linguist working as a systems administrator for NASA, in 1987. It was originally intended as a general purpose UNIX scripting language to make the processing of reports easier. It has undergone a number of transformations since that time, and has evolved into a popular and widely-used programming language, particularly for the creation of CGI scripts. Larry Wall continues to oversee the development of the language, the latest version of which is version 5.10.8, released in December 2007. Perl is available under the GNU General Public License (GPL), and is included in the default installation of many popular operating systems. Perl version 6 is currently being developed.
Perl has been affectionately dubbed the "Swiss Army chainsaw of programming languages", due to the fact that it can be applied to so many different application areas, although it is perhaps most closely related to the C programming language. In 1991, a text called Programming Perl was published, and became the de facto reference work for Perl programmers from version 4 onwards. Perl 5 was released in 1994, and included a virtually re-written interpreter and a mechanism for extending the capabilities of the language through the inclusion of Perl modules, which allowed any sufficiently skilled and motivated Perl programmers to add new features to the language and make them available for others to use. Towards the end of 1995, the Comprehensive Perl Archive Network (CPAN) was established as a repository for Perl modules, and for the Perl programming language itself, and currently holds in excess of fifteen thousand modules by over seven thousand different authors.
Perl is one of the most popular languages used in the creation of Web applications, and is also one of the three Ps associated with the so-called LAMP solution stack (Linux, Apache, MySQL and PHP or Perl or Python) for web development. The core interpreter is written in C, but has become increasingly difficult to maintain over the years. Backward compatibility has been maintained despite the addition of many new features, and code optimisation has been undertaken at the expense of simplicity. As of early 2009, Perl 5 is still being maintained and has already assimilated some of the new features planned for Perl 6, although Perl 6 will be a major overhaul of the language and is not intended to be backwardly compatible with previous versions (there will be a compatibility mode, however).
Users of Microsoft Windows typically install one of the binary distributions of Perl available for Win32, the most popular of which is currently probably ActivePerl from ActiveState. Users of ActivePerl are largely dependent on the repackaged and precompiled modules provided by ActiveState's module repository, which are installed using the Perl Package Manager (PPM). The ActiveState repository is often less rigorously maintained than the Perl mainstream CPAN repository, and to address aspects of using Perl on the Windows platform, http://win32.perl.org was launched by Adam Kennedy on behalf of The Perl Foundation in 2006, with the aim of providing alternative Perl distributions that include an embedded C compiler and build tools to enable users to install modules from the CPAN on a Windows platform.
In Perl, the obligatory "Hello world!" CGI script may be written as follows:
print "Content-type: text/html\n\n";
This CGI script, when invoked, dynamically generates a Web page with the title "Hello World!" that displays the message "Hello World!" in the browser window as a level 1 header. Perl is usually reserved for more serious uses, such as processing Structured Query Language (SQL) queries that either update a database or retrieve data from it. In Perl 5, a database-independent interface is provided between a database and an application by a Database Interface (DBI) module. A Database Driver (DBD) module provides the appropriate driver for a particular database.
PHP is a widely used server-side, cross-platform scripting language that is freely available (including the source code) under the PHP License. The initials come from the earliest version of the language developed by Rasmus Lerdorf in 1995, which was called "Personal Home Page Tools". Two Israeli developers at the Technion IIT, Zeev Suraski and Andi Gutmans, rewrote the parser in 1997, leading to the release of version 3 (now somewhat recursively referred to as PHP: Hypertext Preprocessor) in 1998. Suraski and Gutmans then rewrote PHP's core, producing the Zend Engine in 1999 which was introduced in version 4 of PHP, released in 2000 (they also founded Zend Technologies, which has its headquarters in California and a technology center in Israel). PHP 5 was released in 2004, powered by the new Zend Engine II, and included new features such as improved support for object-oriented programming, and various performance improvements. PHP is now developed and by maintained the PHP Group as a de facto standard. The current release (as of December 2008) is version 5.2.8.
PHP scripts are embedded within a Web page using the opening and closing delimiters <?php and ?>. Only code that appears within these delimiters is parsed by the PHP interpreter. Any other code (chiefly HTML) is sent to the client browser unchanged by the server. A Web page that includes PHP scripting is typically given a file extension of .php. Many of the functions provided by the library files distributed with PHP are similar to those found in the C programming language, as are the control structures used (if ... else conditional statements, and for and while loops, for example). PHP developers may write their own extensions in C to add functionality to the language which can either be compiled into PHP or loaded dynamically at runtime. The PHP Extension Community Library (PECL) provides a repository for such extensions to the PHP language. As of version 4, the PHP parser compiles input into bytecode to be processed by the Zend Engine, resulting in faster execution. Like Perl, PHP is one of the three Ps associated with the LAMP solution stack for web development.
The simple PHP code below checks which browser the client computer is using. The user agent string that the browser sends as part of its request is stored in the variable $user_agent, and is used to determine whether the client browser is Opera, Firefox or Internet Explorer (or none of these).
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
if(strpos($user_agent, 'Opera') !== false)
echo ' You are using Opera';
elseif(strpos($user_agent, 'Gecko') !== false)
echo ' You are using Firefox';
elseif(strpos($user_agent, 'MSIE') !== false)
echo 'You are using Internet Explorer';
echo 'You are using a browser other than Opera, Internet Explorer or Firefox.';