0% found this document useful (0 votes)
20 views50 pages

CH 1

Uploaded by

awelwafi89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views50 pages

CH 1

Uploaded by

awelwafi89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 50

Chapter One

BASICS OF SERVER SIDE


SCRIPTING (SSS)
Introduction to Server Side Scripting

 Server is a computer program or device that provides


a service to another computer program and its user,
also known as the client.
Different types of servers are there. A few examples of
the types of servers available are as follows:
 Web server: a computer program that serves
requested HTML pages or files. In this case, a
web browser acts as the client.
 Application server: a program in a computer in
a distributed network that provides the business logic
for an application program.
Cont…

 Proxy server: software that acts as an intermediary


between an endpoint device and another server from
which a user or client is requesting a service.
 Mail server: an application that receives incoming
emails from local users
 File server: a computer responsible for the central
storage and management of data files
 Database server: this server is responsible for
hosting one or more databases.
 Print server: this server provides users with access
to one or more network-attached printers
Cont…
Server Side

Server-side refers to operations that are performed


by the server in a client–server relationship
 Server-side operations include processing and
storage of data from a client to a server, which can be
viewed by a group of clients.
 Examples of server-side processing include the
creation & adaptation of a database using MySQL
Static Web Sites

The Web sites were made up of a collection of documents


written in the HTML language.
Website is generally a set of related web pages.
web page is a document available on world wide web.
Web Pages are stored on web server and can be viewed
using a web browser.
 Static web pages are loaded on the client’s browser as
exactly they are stored on the web server.
 Static web pages contain only static information. User
can only read the information but can’t do any
modification or interact with the information.
Cont…

Static web sites are created using only HTML


without any Web programming or database design.
 They are only used when the information is no more
required to be modified.
Dynamic website

A dynamic Web site is one with content that is


regenerated every time a user visits or reloads the
site.
 its simple to get information or data using scripting
language that can retrieve the information from the
database.
Google and Yahoo! are examples of dynamic sites,
search engines that create customized pages based
on a key word or phrase you type.
Cont…

The process of creating dynamic Websites.


Web page

 a PHP script can be embedded right in the Web


page. It can generate HTML and images on the fly,
retrieve up-to-date information from a file or
database, encrypt data, remember user preferences,
and so on.
It executes PHP instructions and inserts the results
right back into the Web page before the server sends
the page back to the browser, thus making the page
truly dynamic.
Web sites often handle huge amounts of
information.
Cont…

A database management system is essential for


storing, retrieving, and updating that information.
MySQL, the world’s most popular open source
database, has become the choice for applications that
interact with database-enabled Web sites.
PHP and MySQL works together to produce dynamic
Web pages.
Process of dynamic website
Client side scripting

computer programs on the web that are executed


client-side, by the user’s web browser, instead of
server-side (on the web server).
 is a program that is processed within the client
browser. Example JavaScript
This type of computer programming is an important
part of the Dynamic HTML(DHTML) concept,
enabling web pages to be scripted.
have different changing content depending on user
input, environmental conditions(such as the time of
day), or other variables.
Advantages of client-side scripting

They can be used to validate user input


To interact with the browser
To enhance web pages
Add client/server communication between a browser
and a web server.
offers faster response times, less overhead on the
webserver, and a more interactive application.
 Ideal for altering the page elements without the
need to contact the database.
Limitation of client side scripting

Browser dependency
The browser or scripting host must support the scripting
language and capabilities.
Cannot connect to a back-end server, such as a data base or
file handling systems.
Scripts are restricted from arbitrarily accessing the local
hardware and file system for security reasons.
More development time and effort might be required
Client-side scripts can be viewed by the client using the
browser’s source-viewing capability, so sensitive information
such as passwords or other personally identifiable data
should not be on the client.
Examples of client side scripting

Cascading Style Sheets, Dynamic HTML.


Client-side scripting (javaScript, VBscript)
Java applets etc.
Server-side scripting

web server technology in which a user’s request fulfilled by


running a script directly on the web server to generate dynamic
web pages.
usually used to provide interactive web sites that interface to
databases or other data stores.
Server-side scripting is mostly about connecting web sites to
back end servers such as database.
It is two way communication
Server to client:- web pages can be assembled from back-end
server output.
Client to server:- customer-entered information can be acted up
on. For example, online forms with some drop down lists and
buttons.
Advantage of SSS(server side scripting)

Session management which helps to maintain user identity


Program flexibility
Feasibility
Browser independent
Security
Limitations of server-side scripting are:-
They can be slow due to server programs
Reduce web page appearance, compared to client side
scripting.
It requires the scripting software to be installed on the
server.
…..sss

Server-side scripting has two parts:


The scripting language:- which is a program that
builds dynamic web pages that have scripts
embedded to create dynamic content.
The scripting engine:- which parses and
interprets web pages written in the language.
Examples of SSSL

PHP (hypertext preprocessor)


ASP (active server page)
JSP (java server page)
Cold Fusion, etc.
What is PHP?

 PHP is one of the most popular scripting languages on the


web and it stands for Hypertext Preprocessor.
 PHP is an HTML-embedded scripting language but much
of its syntax is borrowed from C, PERL (Practical
Extraction and Report Language) and Java with some
unique PHP features thrown in.
 PHP is a widely used general-purpose scripting language
that is especially suited for Web development.
 PHP is a scripting language, designed to write Web
scripts, not stand-alone applications (although, with some
extra effort, you can now create applications in PHP).
PHP ….

PHP scripts run only after an event occurs—for


example, when a user submits a form or goes to a
URL.
PHP is a server-side, cross-platform technology.
PHP is a cross platform language and runs on different
platforms such as, Linux/unix, Macintosh or windows
etc.
A Web server application, like Apache or Microsoft’s
IIS (Internet Information Services), is required and all
PHP scripts must be accessed through a URL.
Why we Use PHP?

Simple for developing dynamic Web sites,


PHP runs on different platforms (Windows, Linux, Unix,
etc.)
 PHP is compatible with almost all servers used today
(Apache, IIS, etc.)
 PHP is FREE to download from the official PHP resource
PHP is easy to learn and runs efficiently on the server side
Stability and Portability
Excellent performance,
A very manageable learning curve.
Features of php

Open source:- Simply stated, you can download and use


these applications without a credit card or a free trial
period.
Flexible for integration with HTML: One or more
PHP scripts can be embedded into static HTML files and
this makes client tier integration easy.
Easy to use and Suited to complex projects: It is a
fully featured object-oriented programming language, with
more than 110 libraries of programming functions for
tasks as diverse as math, sorting, creating PDF documents,
and sending email.
Cont…

Fast at running scripts: PHP script execution is


fast and all components
run within the main memory space of PHP.
Platform- and operating-system portable:
Apache and PHP run on many different platforms
and operating systems. PHP can also be integrated
with other web servers.
Third-party Application Support: use of
different databases and access to C libraries, Java
classes, COM objects etc.
How PHP Works?
Common uses of PHP

PHP performs system functions, i.e. from files on a


system it can create, open, read, write, and close them.
PHP can handle forms, i.e. gather data from files, save
data to a file, through email you can send data, return
data to the user.
You add, delete, modify elements within your database
through PHP.
Access cookies variables and set cookies.
Using PHP, you can restrict users to access some pages
of your website.
It can encrypt data.
What is MySQL?

 MySQL is the world’s most popular open-source database.


 MySQL offers excellent performance, portability, and
reliability, with a moderate learning curve and little to no
cost.
 MySQL is a database management system (DBMS) for
relational databases.
 A relational database uses multiple tables to store
information.
 Further, relational databases are more searchable and allow
for concurrent users.
 PHP has always had good support for MySQL, and that is
even more true in the most recent versions of the language.
Process of php script

How most of the dynamic Web applications will work both MySQL and php
Basic Syntax

A PHP script is a file (ending with a .php extension) consisting of


text, HTML, and PHP instructions interspersed throughout the file.
A PHP scripting block always starts with <?php and ends with ?>.
<?php --- is the opening tag
?> --- is the closing tag.
Anything written within these tags will be treated by the Web server
as PHP.
The PHP interpreter will process the code.
Any text outside of the PHP tags is immediately sent to the Web
browser as regular HTML.
Cont…

 Most Web servers use .html for standard HTML pages and .php for
PHP files.
 A PHP file normally contains HTML tags, just like an HTML file,
and some PHP scripting code.
Example
<?php
Echo“ This is php”;
?>
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.
PHP Comments

 The PHP language supports three methods of commenting:


1. The “Shell” Method (i.e. #) - In this method, the comments
begin with the hash tag symbol.
Example: # This Class is the smart class .
2. The “C” Method (i.e. /* */) - This method is taken from the C
language. It allows you to create multi-line comments.
Example: /* This class
contains
IT third year students. */
3. The “C++” Method (i.e. //)- This method is used to write a single-
line comment
Example: // This is a PHP class.
Cont…

Example
<?php
echo "This is the code for comment clarification<br>";
//echo"this is this first type of single line comment";
#this is the second type of single line comment
// multiple line comment start here
/*
you can write any clarification about your code here
*/
echo“Those are a type of comments in php";
?>
Sending Data to the Web Browser

 To build dynamic Web sites with PHP, the first step is knowing how
to send data to the Web browser.
 PHP has a number of built-in functions for this purpose.
 The most common being echo and print.
 Example:
echo 'Hello, world!';
echo "What's new?";

print 'Hello, world!';


print "What's new?";

 PHP is built-in functions are case insensitive.


 So ECHO, echo, eCHo, and so forth will all work.
Question

What is the difference


between echo and print???
Cont…

Example:
<html>
<body>
<?php
echo "Hello World";
?>
</body>
</html>
Working with Variables

 Variables are containers used to temporarily store values.


 These values can be numbers, text, or much more complex
data.
 PHP supports eight types of variables.
 These include four scalar (single-valued) types
 Boolean (TRUE or FALSE),
 integer,
 floating point (decimals),
 strings (characters);
 Resources (interacting with databases) and
 NULL(which is a special type that has no value).
 Two non-scalar(multivalued)
 arrays and objects;
Working with Variables

Variable in PHP gives access to memory storage.


Variable names in PHP follow certain syntactical rules:
 start with a dollar sign ($), for example, $username.
 can contain a combination of letters, numbers, and the underscore,
for example, $my_report1.
 The first character after the dollar sign must be either a letter or an
underscore (it cannot be a number).
 Variable names in PHP are case sensitive!
In PHP a variable does not need to be declared
before being set.
It automatically converts the variable to the correct data
type, depending on how they are set.
Cont…

Variables can be assigned values using the equals sign


(=), also called the assignment operator.
To display the value of a variable, you can print the
variable without quotation marks:
 Echo $some_var;
Or variables can be printed within double quotation
marks:
 Echo "Hello, $name";
You cannot print variables within single quotation
marks:
 Echo 'Hello, $name'; // Won't work!
Cont…

Example:
<?php
$txt1="Hello World";
$txt2="1234";
echo $txt1 . " " . $txt2 ;
?>
The output of the script above will be: "Hello World
1234".
Manipulating Strings

 A string is a sequence of letters, numbers, special characters and arithmetic


values or combination of all.
 A string variable is used to store and manipulate a piece of text.
 String variables are used for values that contains character strings.
 To make a string variable, assign a string value to a valid variable name:
 $first_name = ‘IT Third year';
 $today = ‘January 21, 2022';
 When creating strings, you can use either single or double quotation marks to
encapsulate the characters.
 You must use the same type of quotation mark for the beginning and the end of the
string.
 If that same mark appears within the string, it must be escaped:
 $var = "Define \"platitude\", please.";
 Or you can also use the other quotation mark type:
 $var = 'Define "platitude", please.';
Cont…

Concatenation is like addition for strings, whereby


characters are added to the end of the string.
It is performed using the concatenation operator,
which is the period (.):
 $city= 'Seattle';
 $state = 'Washington';
 $address = $city . $state; //SeattleWashington
To improve upon this, you could write
 $address = $city . ', ' . $state; //Seattle, Washington
Most used string functions

strlen():returns the length of a string


str_word_count():counts the number of words in a
string
strrev():reverses a string:
strpos():searches for a specific text within a string.
str_replace():replaces some characters with some
other characters in a string.
strtoupper():change string text to uppercase
Cont…

 echo strlen("Hello world!"); //out put 12


 echo strpos("Hello world!","world"); //out put 6

 echo str_word_count("Hello world!"); // outputs 2

 echo strrev("Hello world!"); // outputs !dlrow olleH

 echo str_replace("world", “students", "Hello world!"); //


outputs Hello students!
 $originalString = "String Capitalization 1234";

 $upperCase = strtoupper($originalString);

 echo "Old string - $originalString <br />";

 echo "New String - $upperCase";

// outputs
Old string - String Capitalization 1234
New String - STRING CAPITALIZATION 1234
Manipulating Numbers

PHP has both integer and floating-point (decimal) number


types.
These two types can be classified under the generic title
numbers without losing any valuable distinction.
Valid number-type variables in PHP can be anything like:
 8
 3.14
 10980843985
 -4.2398508
 4.4e2
Notice that these values are never quoted.
Quoted numbers are strings with numeric values nor do they
include commas to indicate thousands.
Cont…

A number is assumed to be positive unless it is preceded


by the minus sign (-).
Numbers can be used with the standard arithmetic
operators and there are also functions built into PHP.
Two common ones are round( ) and
number_format( ).
The former rounds a decimal to the nearest integer:
 $n = 3.14;
 $n = round ($n); // 3
It can also round to a specified number of decimal places:
 $n = 3.142857;
 $n = round ($n, 3); // 3.143
Cont…

The number_format( ) function turns a number


into the more commonly written version, grouped
into thousands using commas:
 $n = 20943;
 $n = number_format ($n); // 20,943
This function can also set a specified number of
decimal points:
 $n = 20943;
 $n = number_format ($n, 2); //20,943.00
constants

 Constants are used to temporarily store a value.


 To create a constant, you use the define( ) function instead of
the assignment operator (=):
 define ('NAME', value);
 As a rule of thumb, constants are named using all capitals,
although this is not required.
 Most importantly, constants do not use the initial dollar sign as
variables do.
 A constant can only be assigned a scalar value, like a string or a
number:
 define ('USERNAME', ‘Tom');
 define ('PI', 3.14);
 And unlike variables, a constant’s value cannot be changed
Cont…

With that code, PHP literally prints Hello,


USERNAME and not the value of the USERNAME
constant.
Because there is no indication that USERNAME is
anything other than literal text.
Instead, either print the constant by itself:
 echo 'Hello, ';
 echo USERNAME;
Or use the concatenation operator:
 echo 'Hello, ' . USERNAME;
d
En

You might also like