Table of Contents |
Recall that there are two sides to scripting for websites and web applications: client side and server side. Furthermore, scripting is the ability to write programming code that will be executed either by a webserver or a client’s browser in order to manipulate content within the Document Object Model (DOM) and provide functionality to the user interface.
As a brief recap, remember that JavaScript is the primary scripting language used on the client side. JavaScript is executed by the client’s web browser and is able to manipulate content on the webpage in real time. However, once the HTML, CSS, and JavaScript code reaches the web browser, JavaScript is pretty much on its own and cannot access resources on the webserver, with the exception of issuing asynchronous AJAX calls to the resources on the server.
Let us explore the concepts and applications of server-side scripting. We will briefly discuss some of the options for server-side scripting languages, but we will focus on PHP.
Server-side scripting refers to code that resides on and is executed by the webserver. The script files on the server can be used in a number of ways:
Using server-side scripting begins by ensuring the scripting language’s processing engine is installed and configured on the webserver. When using the Microsoft webserver Internet Information Service (IIS), support for ASP.NET scripts comes pre-installed. However, if you want to use PHP, Ruby, Java, or server-side JavaScript using NodeJS, then these will need to be installed onto the webserver and configured. The configuration of the scripting engine is beyond the scope of this course but typically involves associating file extensions like .js, .php, or .cs with the correct scripting engine. This way, when an HTTP request comes into the server and requests a file such as “loginHandler.php,” as the requested file contains the .php file extension, the server will first pass the file to the PHP scripting engine and then return the resulting content back to the client.
Below is a table of commonly used server-side scripting languages:
| Title | Description |
|---|---|
| ASP.NET C# / VB | ASP (Active Server Page) runs on Microsoft’s powerful .NET framework and is a general-purpose scripting language. Additionally, ASP.NET supports both C# (C-Sharp) as well as Visual Basic (VB) and can be developed using Microsoft’s Visual Studio IDE applications. |
| PHP | PHP is an open-source, general-purpose, server-side scripting language. Being open source, PHP provides an incredible amount of flexibility and compatibility with other technologies. |
| Python | Python is a general-purpose, server-side scripting language that has gained popularity due to its powerful yet simplified coding syntax. Furthermore, lots of frameworks and extensions have been developed for and around Python. |
| NodeJS | NodeJS is not just a server-side scripting language but is also a runtime environment that can run and host its own applications and webserver. NodeJS is often used to program webservers themselves, as well as provide scripting support for existing webservers through server-side JavaScript. |
| Ruby | Ruby is a general-purpose, server-side scripting language designed with the goal of making programming fun. Ruby removes some of the tedious and problematic burdens of memory management and concurrency. |
| Java | Java is a powerful server-side and general-purpose programming language that supports object-oriented coding and concurrency and is designed to be executable on most digital computer systems. Java introduced the term “write once, run anywhere.” |
| GoLang | GoLang is one of the newer programming languages from Google that was designed for lightweight web services that run on mobile devices. The main benefit of the lightweight web service architecture is that it enables integration with a wide range of other programming languages. |
So, how does one go about choosing the ideal language for one's project?
The first consideration would be the project requirements and the type of application being developed. For example, PHP tends to be ideal for content management systems and e-commerce platforms, while Python is more popular for data analysis and machine learning.
The second consideration is the current or desired computing environment. The current computing environment (i.e., Microsoft vs. Apple vs. Linux, etc.) may also introduce compatibility or performance concerns with different scripting languages. One example is the use of Ruby on Rails, which is a framework that runs on top of Ruby and requires the Apache or Nginx webserver. These two webservers run better on Linux-based operating systems.
Additional considerations include the following:
Scripting Language Processing Engine
Server-based software that executes language-specific code contained within a script file, replacing the script code with the text-based output that results from the code’s execution.
Internet Information Service (IIS)
Server-based webserver software developed by Microsoft that hosts files and resources online and responses to HTTP requests.
ASP.NET
Server-side framework designed for web development and server-side scripting used for creating dynamic webpage content.
Java
A common, high-level object-oriented programming language that can be used as a server-side scripting language, as well as platform-independent applications.
Python
A popular, high-level general-purpose programming language that works well as a server-side scripting language.
Ruby on Rails
A server-side web application framework designed for rapid development of model-view-controller-based web services, pages, and databases.
Apache
A popular, free, open-source HTTP server.
Nginx
A free, flexible, open-source HTTP server.
PHP (PHP: Hypertext Preprocessor) is a powerful, general-purpose, open-source scripting language. PHP can be used to generate entire webpages, including HTML, CSS, and JavaScript, as well as create small or complex web services. PHP is also a great language for handling web form submissions, generating emails, connecting to databases, and more.
PHP files are plain-text files that have the .php file extension. Any and all PHP code must be surrounded in the following syntax:
EXAMPLE
PHP script container:<?php //code goes here ?>
The PHP script container can be placed anywhere within a .php file and will be executed and removed from the code file, leaving behind any resulting output of the code. Once the file has been executed, the remaining code and data get transmitted back to the system that made the request. This allows us to use PHP in two key ways:
1. Build an entire HTML and CSS webpage with PHP containers and code strategically placed throughout the document and saved as a .php file.
2. Process an operational request, such as a form submission, login, registration, and so on.
The great thing about server-side scripts is that they can be triggered by just about any event by simply tying the event to a JavaScript function that issues an AJAX request.
Source: This Tutorial has been adapted from "The Missing Link: An Introduction to Web Development and Programming " by Michael Mendez. Access for free at https://open.umn.edu/opentextbooks/textbooks/the-missing-link-an-introduction-to-web-development-and-programming. License: Creative Commons attribution: CC BY-NC-SA.