Web Server and Server Side Scripting
Web Server and Server Side Scripting
Outline
• Introduction
• Web hosting
• Types of hosting
• Web deployment
• Apache server configuration
• Website securites
• Introduction PHP
• Scripting with PHP - Variables, Data Types, Functions, Forms
Web Server
• A web server is server software, that can satisfy client HTTP requests on the public World Wide
Web or also on private LANs and WANs.
• The primary function of a web server is to store, process and deliver web pages to clients.
• This primary function definition was good a few decades ago but nowadays it is better to use the
terms of Web contents and / or Web resources instead of Web Pages because it cover all kind of
contents that can be delivered to clients by web server.
• Examples of Web contents may be HTML files, XHTML files, image files, style sheets, scripts,
other types of generic files that may be downloaded by clients, etc…
• A user agent, commonly a web browser or web crawler, initiates communication by making a
request for a specific resource using HTTP and the server responds with the content of that
resource or an error message if unable to do so.
• Commonly used web servers,
• For PHP: Apache
• For ASP: IIS
• For JSP: Tomcat, Glassfish
Web hosting and Deployment
• Online Presence
• Reliability and Uptime
• Performance and Speed
• Scalability and Flexibility
• Security and Data Protection
• Technical Support and Maintenance
Types of Web Hosting
• Shared hosting
• Virtual Private Server (VPS)
• Dedicated Hosting
• Cloud Hosting
Shared Hosting
• The Apache HTTP Server ("httpd") was launched in 1995 and it has
been the most popular web server on the Internet since April 1996.
• We can download and install apache web server separately from
http://httpd.apache.org/download.cgi
• We can also download Apache web server with bundle like XAMPP,
WAMP or LAMP.
• XAMPP is the most popular PHP development environment consist of Apache,
MariaDB, PHP, Perl and many other packages.
• WAMP is popular PHP development environment for Windows OS.
• LAMP is popular PHP development environment for Linux based OS.
• We are going to use XAMPP bundle as it has installable versions of
Windows as well as Linux.
• We can download XAMPP and install XAMPP from
https://www.apachefriends.org/index.html
Installing XAMPP
•The PHP code is enclosed in special start and end processing instructions
<?php and ?> that allow you to jump into and out of "PHP mode."
PHP Introduction
PHP Introduction
•This program is extremely simple and you really did not need to use
PHP to create a page like this. All it does is display: Hello World using the
PHP echo() statement.
• Variables in a program are used to store some values or data that can be
used later in a program.
• The variables are also like containers that store character values, numeric
values, memory addresses, and strings.
• PHP has its own way of declaring and storing variables.
• There are a few rules, that need to be followed and facts that need to be
kept in mind while dealing with variables in PHP.
PHP Variables
• One must keep in mind that variable names in PHP names must
start with a letter or underscore and no numbers.
• PHP variables are case-sensitive, i.e., $sum and $SUM are treated
differently.
Data types used by PHP to
declare or construct variables:
•Integers
•Doubles
•NULL
•Strings
•Booleans
•Arrays
•Objects
•Resources
Example
<?php
$num = 20;
global_var();
?>
Variable Scopes
Code Reusability: PHP functions are defined only once and can
be invoked many times, like in other programming languages.
Less Code: It saves a lot of code because you don't need to write
the logic many times. By the use of function, you can write the
logic only once and reuse it.
PHP Functions
Syntax
function functionname()
{
//code to be executed
}
PHP Functions
<?php
function sayHello(){
echo "Hello PHP Function";
}
sayHello();//calling function
?>
Output:
Hello PHP Function
PHP Function Arguments
File: functionarg.php
<?php
function sayHello($name){
echo "Hello $name<br/>";
}
sayHello("Sonoo");
sayHello("Vimal");
sayHello("John");
?>
Output:
Hello Sonoo Hello Vimal Hello John
PHP Function Arguments
Output
Hello Call By Reference
PHP Function: Default Argument
Value
We can specify a default argument value in function. While
calling PHP function if you don't specify any argument, it will
take the default argument. Let's see a simple example of using
default argument value in PHP function.
File: functiondefaultarg.php
<?php
function sayHello($name="Sonoo"){
echo "Hello $name<br/>";
}
sayHello("Rajesh");
sayHello();//passing no value
sayHello("John");
?>
Output:
Hello Rajesh
Hello Sonoo
Hello John
PHP Function: Returning Value
Let's see an example of PHP function that returns value.
File: functiondefaultarg.php
<?php
function cube($n){
return $n*$n*$n;
}
echo "Cube of 3 is: ".cube(3);
?>
Output:
Cube of 3 is: 27
PHP Form Handling
The PHP superglobals $_GET and $_POST are used to collect form-data.
PHP - A Simple HTML Form
The example below displays a simple HTML form with two input fields and
a submit button:
Example:
Introduction to PHP form processing
To create a form, you use the <form> element as follows:
<form action="form.php" method="post"> </form>
•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.
Introduction to PHP form processing
• 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.
• HTTP POST method