Dream Science and
Technology College
Producing Server-side Scripting for
Dynamic web pages
By: Bedru Y.
(MSc.)
Oct,201 7E.C
Dessie, Ethiopia
Overview of the module
• Dynamic Web page
• Web Scripting language
o Server-side Script
o Client-side script
• Produce Server-side Script
Dynamic web pages
Dynamic web pages: are web pages that can change their content or layout
dynamically.
Usually dynamic web pages changes based on user interaction or other events.
Unlike static web pages, which display the same content to every user.
Dynamic web pages can display different content to different users or update the
displayed content without requiring the user to reload the page.
Key features of Dynamic web pages:
User interaction
Server-side scripting
Database integration
Client-side scripting
Dynamic web pages
User interaction: content changes based on user actions such as clicking
button, filling out forms, or navigating the site.
Server-Side Scripting: often utilize server side languages
(like,PHP,python,Node.js) to generate dynamic content.
Database Integration: can retrieve and display data from databases,
ensuring the content is up-to-date and relevant.
Client-side scripting: Uses client-side scripting language(like JavaScript)to
update the web pages without reloading
Dynamic web pages
Let us see the following case study:-
A user logs into a website, and their dashboard displays personalized
information like recent activity, messages, and recommendation.
This information is retrieved from a database and rendered dynamically
based on the user’s profile.
Web Scripting language
When building an online application or simply adding some additional
dynamics to a website, there is a special resource called scripting
languages.
A scripting languages is programming language used for automating
tasks and adding dynamic functionality to web pages and applications.
Web scripting languages are essential for creating dynamic, interactive , and
responsive websites.
They allow developers to write the code that can be executed on either the
client side (in the user’s browsers) or the server side (on the web server)
Web Scripting language
Here’s a look at some of the most commonly used web scripting languages :
1. Client-Side Scripting Languages
These scripts run in the user’s web browsers and are used to create
interactive and engaging web experiences .
Client –side scripting language are used to :
Create the structure of web pages(HTML)
Style and layout the web pages(CSS)
Adding form validation, and animation more(JavaScript)
Example: HTML, CSS, javascript
Web Scripting language
Here’s a look at some of the most commonly used web scripting languages :
2. Server-Side Scripting Languages
These scripts run on the web server and are used to manage the
backend functionality of a website.
Server –side scripting language are used to :
Generate dynamic web page content (PHP)
Handle form submissions
Interact with database
Example:PHP, Python, Node.js , ruby,
Introduction to PHP
PHP is
stands for Hypertext Preprocessor
a widely-used scripting language
free software released
PHP code can be embedded into HTML or XHTML documents
It is executed on the server to generate dynamic web content.
PHP is frequently used together with MySQL, and is one of the key
technologies
Introduction to PHP
Key Features of PHP
Server-side execution: PHP script are executed on the server
Embedded in HTML: PHP code can be easily embedded within HTML
code.
Cross-Platform: PHP runs on various platform like windows, Linux,
macOS and more.
You cannot view the PHP source code by selecting "View source" in the
browser
you will only see the output from the PHP file, which is plain HTML.
This is because the scripts are executed on the server before the result
is sent back to the browser
PHP development Env’t
Steps to set Up a PHP Development Environment
Here’s the comprehensive guide to get you started :
1. Install a web server
• Download and install XAMPP or WAMP server
• Follow the installation prompts and choose the default
setting.
• Once installed, start the Apache server from the control
panel
• PHP is bundled or included with XAMPP and WAMP
2. Install a database server (MySQL is recommended )
• MySQL is included with XAMPP and WAMP
• Follow the installation instruction and choose the
default settings
PHP development Env’t
Steps to set Up a PHP Development Environment
3. Download and install text Editor/IDE
• Visual Studio Code
• Sublime Text
4. Configure IDE for PHP
• Install PHP extensions to your text editor or IDE for
better code completion and debugging.
5. Place your PHP file in your Project directory
• Save the file in the /public folder of the installed server
Basic PHP syntax
A PHP file normally contains HTML tags, just like an HTML file, and some PHP
scripting code.
A PHP scripting block always starts with <?php and ends with ?>
Basic PHP syntax
A PHP scripting block can be placed anywhere in the document
Each code line in PHP must end with a semicolon.
The semicolon is a separator and is used to distinguish one set of
instructions from another.
There are two basic statements to output text with PHP: echo and print.
The default extension of PHP files is: .php.
Basic PHP syntax
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:.
Basic PHP syntax
PHP Variables:
In PHP, a variable is declared using a $ sign followed by the variable
name
Here, some important points to know about variables:
• After declaring a variable, it can be reused throughout the code.
• Assignment Operator (=) is used to assign the value to a variable.
• Syntax of declaring a variable in PHP is given below:
• $variable name=value;
Basic PHP syntax
Rules for declaring PHP variable:
A variable must start with a dollar ($) sign, followed by the variable
name.
PHP variables must start with letter or underscore only.
PHP variable can't be start with numbers and special symbols.
It can only contain alpha-numeric character and underscore (A-z, 0-9,
_).
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.
Basic PHP syntax
PHP Variable: Declaring string, integer, and float
File: variable1.php
Output:
string is: hello string
integer is: 200
float is: 44.6
Basic PHP syntax
Php code to display your first name defined by variable name fname
File:sample.php
<?php
$fname=“Bedru”;
Echo “my name is $fname;
?>
output:
My name is: Bedru
Basic PHP syntax
PHP Variable: Sum of two variables
File: variable2.php
Output:
11
Basic PHP syntax
PHP Variable: case sensitive
• 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
Basic PHP syntax
Note that: To concatenate two or more variables together, use the dot (.)
operator:
<html>
<body>
<?php
$txt1="Hello World";
$txt2="1234";
echo $txt1 . " " . $txt2 ;
?>
</body>
</html>
Basic PHP syntax
Comments in PHP: we use // to make a single-line comment or /* and */ to
make a large comment block.
<html> <body>
<?php
//This is a single comment
/* This is Multiple comment block */
?>
</body>
</html>
PHP Operator
PHP Operators: Operators are used to performing operations on some values.
• In other words, we can describe operators as something that takes some
values, performs some operation on them, and gives a result.
• From example, “1 + 2 = 3” in this expression ‘+’ is an operator. It takes
two values 1 and 2, performs an addition operation on them to give 3.
• Given below are the various groups of operators:
PHP Operator
1. Arithmetic Operators
• The arithmetic operators are used to perform simple
mathematical operations like addition, subtraction,
multiplication, etc.
PHP Operator
2. Logical or Relational Operators
• These are basically used to operate with conditional
statements and expressions. Conditional statements are
Operat
based
or
onName
conditions.
Syntax Operation
And Logical AND $x and $y True if both the operands are true else false
Or Logical OR $x or $y True if either of the operands is true else false
True if either of the operands is true and false if
Xor Logical XOR $x xor $y
both are true
&& Logical AND $x && $y True if both the operands are true else false
|| Logical OR $x || $y True if either of the operands is true else false
! Logical NOT !$x True if $x is false
PHP Operator
3. Comparison Operators These operators are used to compare two elements
and outputs the result in Boolean form. .
Operator Name Syntax Operation
== Equal To $x == $y Returns True if both the operands are equal
!= Not Equal To $x != $y Returns True if both the operands are not equal
<> Not Equal To $x <> $y Returns True if both the operands are unequal
== Identical $x === $y
Returns True if both the operands are equal and are of the
same type
=
!== Not Identical $x == $y
Returns True if both the operands are unequal and are of
different types
< Less Than $x < $y Returns True if $x is less than $y
> Greater Than $x > $y Returns True if $x is greater than $y
<= Less Than or Equal To $x <= $y Returns True if $x is less than or equal to $y
>= Greater Than or Equal
To
$x >= $y Returns True if $x is greater than or equal to $y
PHP Operator
5. Assignment Operators These operators are used to assign values to
different variables, with or without mid-operations.
Operator Name Syntax Operation
= Assign $x = $y
Operand on the left obtains the value of the
operand on the right
+= Add then Assign $x += $y Simple Addition same as $x = $x + $y
-= Subtract then
Assign
$x -= $y Simple subtraction same as $x = $x – $y
*= Multiply then
Assign
$x *= $y Simple product same as $x = $x * $y
/= Divide then Assign
(quotient)
$x /= $y Simple division same as $x = $x / $y
%= Divide then Assign
(remainder)
$x %= $y Simple division same as $x = $x % $y
PHP Operator
6. Increment/Decrement Operators These are called the unary operators as
they work on single operands. These are used to increment or decrement
values.
Operator Name Syntax Operation
++ Pre-Increment ++$x First increments $x by one, then return $x
-- Pre-Decrement - -$x First decrements $x by one, then return $x
++ Post-Increment $x++ First returns $x, then increment it by one
-- Post-Decrement $x- - First returns $x, then decrement it by one
Control structure in PHP
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.
These statements are mainly categorized into following:
• Conditional Statements
• Loop Statements
• Jump Statements
Control structure in PHP
I. Conditional Statements.
Conditional Statements performs different computations or actions depending on
conditions. In PHP, the following are conditional statements
• if statement
• if - else statement
• if - elseif - else statement
• switch statement
If statement
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
}
Control structure in PHP
I. Conditional 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.
if (condition)
{
statements
}
else
{
statements
}
Control structure in PHP
I. Conditional Statements.
if - elseif - else statement-The elseif statement enables us to check multiple
conditions and execute the specific block of statements depending upon the true
if (condition1)
condition among them.
{
statements
}
else if(condition2)
{
statements
}
else if(condition 3)
{
statements
}
•
•
else
{
Statements
}
Control structure in PHP
I. Conditional Statements.
Switch statement- it enables us to execute a block of code from multiple
conditions depending upon the expression..
switch (expression)
case 1: statements
break;
case 2: statements
break;
case 3: statements
break;
default: statements
}
Control structure in PHP
II. Loop 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
Control structure in PHP
II. Loop Statements.
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
}
Control structure in PHP
II. Loop Statements.
do - while loop statement
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);
Control structure in PHP
II. Loop Statements.
For loop statement
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:
for (initialization; condition; increment/decrement)
{
statements
}
Control structure in PHP
II. Loop Statements.
Jump statement
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
o break statemen
o continue statement
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;
Control structure in PHP
II. Loop Statements.
Jump statement
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
• Syntax: continue;