Server Scripting Language Chapter 1&2
Server Scripting Language Chapter 1&2
Administration
Level-IV
This unit is developed to provide you the necessary information regarding the following content
coverage and topics:
Dynamic Functionality of a Website
Web Scripting Language
Web Document Requirements
This unit will also assist you to attain the learning outcomes stated in the cover page.
Specifically, upon completion of this learning guide, you will be able to:
Determine Dynamic Functionality
Explore and Evaluate Web Scripting Languages
Understand Web Document Requirements
1.1. Dynamic Functionality of a website
The dynamic functionality of a website refers to features and capabilities that allow the
website to respond and interact with users in real-time, based on their input or other data.
Unlike static websites, which display the same content to all users, dynamic websites offer
personalized and interactive experiences.
A dynamic web refers to websites that change content in real-time based on user interactions
or data, unlike static websites that display fixed content.
When building an online application or simply adding some additional dynamics to a website,
there is a special resource you need: scripting languages. Learning about them and knowing
which ones to use is essential to enjoy all that the modern web has to offer.
Scripting languages are types of programming languages where the instructions are written
for a run-time environment, to bring new functions to applications, and integrate or
communicate complex systems and other programming languages. You have probably
already heard of PHP, Python, JavaScript, and jQuery.
While all scripting languages are programming languages, not all programming
languages are scripting languages. This means that certain capabilities are exclusive to
either of them, which requires the right amount of knowledge to use the appropriate ones.
A scripting language is a programming language that executes tasks within a special run-
time environment by an interpreter instead of a compiler. They are usually short, fast, and
interpreted from source code or bytecode. Such environments include software applications,
web pages, and even embedded systems in operating system shells and games.
There are two main types of scripting languages: server-side and client-side. They differ
on where the code is run from, which affects not only the actual languages chosen but also
the performance and their capabilities.
The term server-side scripting language refers to those that run off a web server. Since it
performs from the back-end side, the script is not visible to the visitor. Because of that, it is a
more secure approach.
They are often used to create dynamic websites and platforms, handle user queries, and
generate and provide data and others. A famous example of server-side scripting is the use
of PHP in WordPress.
Unlike the above, client-side scripting languages run off the user’s browser. It is usually
performed at the front end, which makes it visible to visitors and makes it less vulnerable to
exploits and leaks. As such, it is often used to build user interfaces and lighter functionality
such as that.
Since it runs locally, they usually provide better performance and, therefore, do not strain
your server.
1. JavaScript
Also sometimes abbreviated as simply “JS”, JavaScript is probably the best-known scripting
language, as it’s a pillar of the web as we know it (right along with HTML and CSS). In fact,
about 98 percent of websites currently on the web use JavaScript.
2. Python
After JavaScript, Python is easily the most popular, best-known scripting language in use
today. Programmers love it for its sheer ease of use and concise syntax systems, as they can
create code significantly more quickly and with less actual typing involved.
Python is also free and open-source, making it a highly accessible scripting language.
Features supported by Python include functional programming paradigms, object-oriented
programming, and more.
3. PHP
However, modern PHP is very much its own standalone scripting language.
PHP features object-oriented programming options and can be easily embedded into HTML
documents of all types. Input is also fairly loose and easy, meaning programmers don’t need
to declare variable data types.
4. Ruby
Ruby’s claim to fame is its flexibility, making it a favorite among web developers of all
types.
Among other things, it takes so much of the guesswork out of creating truly innovative
software. It’s also incredibly easy to learn, thanks to its clean syntax, making Ruby an
especially popular pick for beginning coders.
5. Perl
Perl is a general scripting language that’s been around a very long time since December of
1987, to be exact. It started out as a UNIX language primarily used to process reports. (Its
name even originates from the phrase “practical extraction and reporting language”.)
Perl really began to gain traction throughout the 1990s when coders used it heavily for CGI
(common gateway interface), a specification most often seen today on legacy websites.
However, it remains fairly popular because of its innovation and suitability for text
manipulation tasks.
They are often pointed out as great starting points for those interested in learning
programming. That is because they are considerably easier to learn and use than traditional
languages. This means that you can quickly implement the scripts you need without them
requiring a lot of time and resources to be invested in them.
Since scripting languages run off a remote server or from the visitor’s web browser, they
have another highly valuable benefit: they are portable and cross-platform. This means no
additional software needs to be installed to run them and any browser can execute their
functions under any operating system and platform such as WordPress.
Unlike what happens with traditional programming, scripting languages do not require
compilers to store an executable file to be run.
Instead, they use interpreters, which contributes to a much smaller memory requirement on
the system running them either the server or the user’s local machine.
1. Lack of optimizations
Unlike what happens to most programming languages, scripting languages have each
statement line individually analyzed by the compiler without any optimizations. This might
cause an impact on performance.
2. Slower execution
Additionally, most scripting language interpreters are slower than compilers. That is because
traditional programming languages are usually converted to machine code before being
compiled, thus offering faster execution for the users.
3. Organization requirements
When taking advantage of the benefits of these languages, you might reach a point where
your application or website is filled with them. This requires extra attention to organize
everything and keep track of which scripts you are using. Otherwise, it will be impractical to
maintain them.
To ensure a comprehensive website requirement document, you must ensure you have these
five points checked off:
With these goals defined, your website designer can determine how best to achieve them
when building the site.
As the website owner, you need to know and understand your target audience.
Who are the people that will be visiting and using your website?
Knowing your target audience is one of the crucial requirements for website design because
it’ll determine many of the design decisions for your website.
When determining the technical website development requirements, several vital things must
be considered. As the client, you know your business and audience best, so providing as
much detail as possible about what you envision for your site will help ensure the result
meets your needs. Here are six technical requirements and specs to consider:
Functionality
Site Accessibility
Integrations
Site search
Analytics
Site styles
IV. Define content requirements.
When defining the content requirements for website design, several vital things must be
considered.
PHP is a commanding language widely utilized in web development. To fully harness its
potential, it's essential to set up a robust, reliable PHP development environment on
Windows. This process provides the necessary PHP development tools for Windows it can
help in efficient coding, testing & debugging applications, and ensuring streamlined
efficiency during the transition from development to production.
To set up PHP on Windows, XAMPP proves to be an excellent solution. This free, open-
source software offers an easy-to-navigate platform for PHP development. Bundling essential
core components like PHP, Apache, and MySQL XAMPP's accessibility makes it ideal for
beginners, yet its comprehensive toolset caters to the needs of experienced PHP developers.
This guide outlines the necessary steps to set up a PHP development environment in
Windows using XAMPP, aiming to simplify your coding journey.
In the process of configuration, the next steps are opening XAMPP Control Panel and setting-
up local development server.
Apache HTTP Server, commonly referred to as Apache, is a highly customizable and robust
open-source web server software It interprets and executes the PHP code embedded in your
HTML and sends the resulting data to the client in other words, Apache in the bridge that
connects your PHP scripts to the user's browser.
MySQL, on the other hand, is a relational database management system. It allows you to
store, retrieve, and manipulate databases with which your PHP scripts interact. Whether
building a simple website or a complex web application, data management is a core function,
making MySQL an essential part of the PHP development process.
II.2. Basic syntax of Server-side scripts
When we talk about popular programming languages, usually at the top of the list is PHP, a
favorite among developers and software engineers who use frameworks based on this
language to build modern and multifunctional web pages and applications.
PHP is one of the most popular scripting languages and works on the server side. Its
acronym means “Hypertext Preprocessor” in Spanish and it is embedded in HTML. It allows:
creating personalized web content, sending and receiving cookies, evaluating form data sent
from a browser, etc.
In addition to its features, it has integration with several popular databases like Postgre SQL,
Oracle, Sybase, SQL, and MySQL. It also handles forms, saves data to files, and collects data
from files.
A PHP script can be placed anywhere in a document. This script starts with <?php and ends
with?>. We present an example:
The default extension of PHP files is: .php. A PHP file usually contains HTML tags and some
PHP script code.
The following is an example of a simple PHP file, with a script that uses a built-in echo
function to output the text "Hello world!" On a website:
II.2.2. PHP Variables
In PHP, a variable is declared using a $ sign followed by the variable name. Here, some
important points to know about variables:
As PHP is a loosely typed language, so we do not need to declare the data types of
the variables. It automatically analyzes the values and makes conversions to its
correct datatype.
After declaring a variable, it can be reused throughout the code.
Assignment Operator (=) is used to assign the value to a variable.
$variablename=value;
A variable must start with a dollar ($) sign, followed by the variable name.
It can only contain alpha-numeric character and underscore (A-z, 0-9, _).
A variable name must start with a letter or underscore (_) character.
A PHP variable name cannot contain spaces.
One thing to be kept in mind that the variable name cannot start with a number or
special symbols.
PHP variables are case-sensitive, so $name and $NAME both are treated as different
variable.
Let's see the example to store string, integer, and float values in PHP variables.
File: variable1.php
Output:
string is: hello string
integer is: 200
float is: 44.6
File: variable2.php
Output:
11
In PHP, variable names are case sensitive. So variable name "color" is different from Color,
COLOR, COLor etc.
File: variable3.php
Output:
My car is red
Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4
My house is
Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5
My boat is
Output:
hello
hello
File: variableinvalid.php
Output:
Parse error: syntax error, unexpected '4' (T_LNUMBER), expecting variable
(T_VARIABLE)
or '$' in C:\wamp\www\variableinvalid.php on line 2
PHP data types are used to hold different types of data or values. PHP supports 8 primitive
data types that can be categorized further in 3 types:
i. Scalar Types (predefined)
ii. Compound Types (user-defined)
iii. Special Types
It holds only single value. There are 4 scalar data types in PHP.
i. Boolean
ii. integer
iii. float
iv. string
PHP Data Types: Compound Types
It can hold multiple values. There are 2 compound data types in PHP.
i. array
ii. object
Just like any other programming language, PHP also supports various types of operations like
arithmetic operations (addition, subtraction, etc), logical operations (AND, OR etc),
Increment/Decrement Operations, etc. Thus, PHP provides us with many operators to
perform such operations on various operands or variables, or values. These operators are
nothing but symbols needed to perform operations of various types. Given below are the
various groups of operators:
Arithmetic Operators
Logical or Relational Operators
Comparison Operators
Conditional or Ternary Operators
Assignment Operators
Array Operators
Increment/Decrement Operators
String Operators
i. Arithmetic Operators
The arithmetic operators are used to perform simple mathematical operations like addition,
subtraction, multiplication, etc. Below is the list of arithmetic operators along with their
syntax and operations in PHP.
These operators are used to compare two elements and outputs the result in Boolean form.
Here are the comparison operators along with their syntax and operations in PHP.
These operators are used to compare two values and take either of the results
simultaneously, depending on whether the outcome is TRUE or FALSE. These are also
used as a shorthand notation for if…else statement that we will read in the article on
decision making.
Syntax:
Here, the condition will either evaluate as true or false. If the condition evaluates to True,
then value1 will be assigned to the variable $var otherwise value2 will be assigned to it.
v. Assignment Operators
These operators are used to assign values to different variables, with or without mid-
operations. Here are the assignment operators along with their syntax and operations, that
PHP provides for the operations.
These operators are used in the case of arrays. Here are the array operators along with their
syntax and operations, that PHP provides for the array operation.
These are called the unary operators as they work on single operands. These are used to
increment or decrement values.
This operator is used for the concatenation of 2 or more strings using the concatenation
operator (‘.’). We can also use the concatenating assignment operator (‘.=’) to append the
argument on the right side to the argument on the left side.
PHP comments can be used to describe any line of code so that other developer can
understand the code easily. It can also be used to hide any code.
PHP supports single line and multi line comments. These comments are similar to C/C++
and Perl style (Unix shell style) comments.
Output:
In PHP, we can comment multiple lines also. To do so, we need to enclose all lines
within /* */. Let's see a simple example of PHP multiple line comment.
Control structures are an essential part of any programming language and PHP is no
exception. They provide the ability to control the flow of execution in a program based on
certain conditions. In other words, they allow you to make decisions in your code and
execute different blocks of code based on those decisions. This helps to simplify complex
tasks, making it easier to write and maintain the code.
I. Conditional Statements
The if statement is used to test a specific condition. If the condition is true, a block of code
(if-block) will be executed.
Syntax:
if (condition)
{
statements
}
if - else statement
The if-else statement provides an else block combined with the if statement which is executed
in the false case of the condition.
Syntax:
if (condition)
{
statements
}
else
{
statements
}
The elseif statement enables us to check multiple conditions and execute the specific block of
statements depending upon the true condition among them.
Syntax:
if (condition1)
{
statements
}
else if (condition2)
{
statements
}
else if (condition3)
{
statements
}
.
.
else
{
statements
}
switch statement
The switch statement enables us to execute a block of code from multiple conditions
depending upon the expression.
Syntax:
switch (expression)
{
case 1: statements
break;
case 2: statements
break;
case 3: statements
break;
.
.
default: statements
}
Sometimes we may need to alter the flow of the program. If the execution of a specific code
may need to be repeated several numbers of times then we can go for loop statements.
In PHP, the following are loop statements
while loop
do - while loop
for loop
A. while loop statement
With the while loop we can execute a set of statements as long as a condition is true. The
while loop is mostly used in the case where the number of iterations is not known in advance.
Syntax:
while (condition)
{
statements
}
The do-while loop will always execute a set of statements at least once and then execute a set
of statements as long as a condition is true.
Syntax:
do
{
statements
} while (condition);
With the for loop, we can execute a set of statements specified number of times. The for loop
is mostly used in the case where the number of iterations is known in advance.
Syntax:
Jump statements in PHP are used to alter the flow of a loop like you want to skip a part of a
loop or terminate a loop.
In PHP, the following are jump statements
break statement
continue statement
A. break statement
The break is a keyword in PHP which is used to bring the program control out of the loop. i.e.
when a break statement is encountered inside a loop, the loop is terminated and program
control resumes at the next statement following the loop.
Syntax:
break;
B. continue statement
The continue statement in PHP is used to bring the program control to the beginning of the
loop. i.e. when a continue statement is encountered inside the loop, remaining statements are
skipped and loop proceeds with the next iteration.
The continue statement skips the remaining lines of code inside the loop and start with the
next iteration. It is mainly used for a particular condition inside the loop so that we can skip
some specific code for a particular condition.
Syntax:
continue;
JavaScript is, like PHP, one of the most popular programming languages. It can be defined as
a high-level, dynamic, interpreted language used with HTML web applications. It is also used
for non-web documents such as PDFs and desktop widgets.
It is up to the developer to choose which programming language best suits the demands of the
project in question: JavaScript or PHP.
When a user submits a form, PHP takes charge of processing the data. This involves
accessing the form elements using super global variables like $_POST and $_GET.
Understanding the nuances of form submission and super global variables is fundamental to
effective user input handling.
To create a form, you use the <form> element as follows:
action: specifies the URL that processes the form submission. In this example,
the form.php will process the form.
method: specifies the HTTP method for submitting the form. The most commonly
used form methods are POST and GET. In this example, the form method is post.
The form method is case-insensitive. It means that you can use either post or POST. If you
don’t specify the method attribute, the form element will use the get method by default.
Typically, a form has one or more input elements including text, password, checkbox, radio
button, select, file upload, etc. The input elements are often called form fields. An input
element has the following important attributes name, type, and value. The name attribute will
be used for accessing the value in PHP.
Get request is the default form request. The data passed through get request is visible on the
URL browser so it is not secured. You can send limited amount of data through get request.
Let's see a simple example to receive data from get request in PHP.
File: form1.html
File: welcome.php
<?php
$name=$_GET["name"];//receiving name field value in $name variable
echo "Welcome, $name";
?>
Post request is widely used to submit form that have large amount of data such as file upload,
image upload, login form, registration form etc. The data passed through post request is not
visible on the URL browser so it is secured. You can send large amount of data through post
request.
Let's see a simple example to receive data from post request in PHP.
File: form1.html
<form action="login.php" method="post">
<table>
<tr><td>Name:</td><td> <input type="text" name="name"/></td></tr>
<tr><td>Password:</td><td> <input type="password" name="password"/></td></tr>
<tr><td colspan="2"><input type="submit" value="login"/> </td></tr>
</table>
</form>
File: login.php
<?php
$name=$_POST["name"];//receiving name field value in $name variable
$password=$_POST["password"];//receiving password field value in $password variable
echo "Welcome: $name, your password is: $password";
?>
Output:
Working with Database
There are 3 types of methods in PHP to connect MySQL database through the backend:
I. MySQL
II. MySQLi
III. PDO
mysql() is now obsolete because of security issues like SQL injection etc., but the other two
are being actively used.
I. MySQLi
MySQLi is an API that serves as a connector function, linking the backend of PHP
applications to MySQL databases. It is an improvement over its predecessor, offering
enhanced safety, speed, and a more extensive set of functions and extensions.MySQLi was
introduced with PHP 5.0.0, and its drivers were installed in version 5.3.0. The API was
designed to support MySQL versions 4.1.13 and newer.
II. PDO
The PHP Data Objects (PDO) extension is a Database Abstraction Layer that serves as an
interface for the backend to interact with MySQL databases. It allows for changes to be made
to the database without altering the PHP code and provides the flexibility to work with
multiple databases. One of the significant advantages of using PDO is that it keeps your code
simple and portable.
PHPMyAdmin
The operations like managing databases, tables, relations, columns, indexes, permissions,
users, etc., on MySQL and MariaDB, phpMyAdmin is also used in performing
administrative-level tasks such as database creation and query execution.
phpMyAdmin supports RTL and LTR languages, so many users can easily use this software.
It can help you run MySQL queries, repair, optimize, check tables, and execute other
database management commands.
Website security is a primary consideration in web development but it is often not taken
seriously by a lot of website owners. If you have built a secure website, then you must have
sought out the services of a security expert who spots areas of weaknesses in your system and
also carry out routine maintenance checks for new flaws and vulnerabilities. These are the
minimum requirements for any safe website and I have grouped them into 10 must-have
features for your website.
a. Registry lock
A skilled hacker can take control of an unsecured domain, alter the
configurations and redirect the site elsewhere. Apart from the embarrassment that such a
breach might bring, there could also be potential legal consequences. In 2003, the New York
Times had to deal with the consequences of such a breach.
With a registry lock feature, it becomes very difficult for a domain to be hijacked or its DNS
configurations altered by a third party without rigorous procedures. A registry lock demands
multiple party authorization from registrar and registry before alterations to the domain can
be made. This is a fundamental requirement for bigger organizations especially. Installing
this feature requires a bit of manual effort and companies typically charge for this service.
b. Hotlink protection
Some sites can take images and hyperlinks from your website and display them on their
pages, essentially stealing your data. This process is called hotlinking. Hotlinking also affects
your bandwidth and disk space of your site so preventing this is crucial. You can protect your
website from this theft of your data by making use of special preventive tools available.
c. Spam stop feature
If you are a frequent user of the internet, it is impossible not to encounter ads and
commercials and these are increasingly using up a lot of online space. A little pop-up here or
there might be benign and users often want to support their favorite brands. Sometimes, these
pop-ups are not so benign and can cause your site to become infected with spam and this
could be bad for user experience. As a business owner, you want your audience to get a
pleasant experience and one way of doing this is by investing in spam stop feature.
d. DDOs attack protection
Distributed denial of service attacks is a common nuisance most sites have to deal with. But
you want these attacks to be as infrequent as possible as they can cause your site to become
spammed if they originate from multiple points. These attacks can also cause your site to run
slower than normal. Your web hosting company can also provide protection against these
kinds of attacks.
e. Secure sockets layer (SSL protection)
This feature provides privacy and security of communication done over the web. This is
especially important if you want you want to sell products or services on your site. SSL
protects the integrity of your website in two basic ways:
i. It creates a secure network between users and tracks every message that is
exchanged over the internet. Some web hosting companies use an encryption
service called a secure shell host (SSH). SSH reduces the need for additional
security installations. SSL employs “optional session caching” in optimizing the
connections between networks.
ii. It employs a mechanism called symmetric cryptography to maintain complete
privacy during web communication between parties. It is also particularly useful
when the communication involves transactions of a financial nature.
f. Two-Step verification
This is also known as two-factor authentication (2FA). It is a security feature that requires
owners of online accounts to produce two authentication factors rather than one. Accounts
that require just one factor for their authentication are known as single-factor authentication
(SFA) accounts. An example of an SFA account would be one that requires a password for
access while an example of a 2FA account would be your bank account as you would require
your debit card and a pin before withdrawing money from an ATM.
The dual-factor authentication is a very powerful security measure and as a rule, you should
never patronize a domain company that does not provide a two-step verification process for
all its user accounts.
Your web security provider would want to focus on how user data can be obtained and
manipulated by an external party causing it to be misinterpreted by the browser.
j. Data backup
Website data breaches and loss are always a possibility. As undesirable as they may be, it is
wise to have a content backup plan in the event of a breach. Hosting companies offer data
backup services that ensure you do not lose your data even if you are compromised and you
will be able to get your website up and running within a few hours even if you come under
damaging attack.