0% found this document useful (0 votes)
30 views19 pages

Web Server

Uploaded by

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

Web Server

Uploaded by

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

Web Page

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.

A server is a computer that serves information to other computers. These computers, called
clients, can connect to a server through either a local area network (LAN) or a wide area
network (WAN), such as the Internet.

Types of servers:

1.Proxy Servers

The Proxy server is responsible for a connection between a client(web browser or an app)
with and an external server to entertain the request for connection, performance enhancement,
and accessibility.

2.Online Gaming Server

Gaming server has gained its popularity in a recent decay. This type of server is responsible
for connecting hundreds of gamers around the world to an external server(s) for accessing
gaming data.

3.Chat Servers

This server enables a number of people to share information in the environment of an internet
newsgroup that offer real-time discussion capabilities.
4.News Servers

They work as a source of distribution and delivery for hundreds of available public
newsgroups accessible over the USENET news network.

5.-Groupware Servers

It is software that is designed to make the users able to work together, regardless of their
location, through the Internet or a corporate Intranet and to work together in a virtual
environment.

6.Fax Servers

Those organizations that want to reduce the incoming and outgoing telephone resources; a
fax server is an ideal solution

7..FTP Server

File Transfer Protocol (FTP ) is one of the oldest server types. It is responsible for
transferring files from server to a computer and vice versa.

8.Application Servers

Application servers have lion’s share in computer territory between database servers and the
end user, where servers are often connected to the two.

Serves all the application operations between users and an organization backenend business
application or database.

9.Internet Relay chat:Real time communication over internet.

\
Web server is a computer where the web content is stored. Basically web server is used to
host the web sites.

The basic objective of the web server is to store, process and deliver web pages to the users
.This intercommunication is done using Hypertext Transfer Protocol (HTTP). These web
pages are mostly static content that includes HTML documents, images, style sheets, test etc.
Apart from HTTP, a web server also supports SMTP (Simple Mail transfer Protocol) and FTP
(File Transfer Protocol) protocol for emailing and for file transfer and storage.

Web Server Working

Web server respond to the client request in either of the following two ways:

● Sending the file to the client associated with the requested URL.
● Generating response by invoking a script and communicating with database
● When client sends request for a web page, the web server search for the requested
page if requested page is found then it will send it to client with an HTTP response.
● If the requested web page is not found, web server will the send an HTTP
response:Error 404 Not found.
● If client has requested for some other resources then the web server will contact to the
application server and data store to construct the HTTP response.
● Web server :Basically used to Generate or transfer the static data like any image or
file from the server to client.

Different Types of protocol

​ Transmission Control Protocol (TCP):: TCP is a popular communication protocol


which is used for communicating over a network. It divides any message into series
of packets that are sent from source to destination and there it gets reassembled at
the destination.

​ Internet Protocol (IP); IP is designed explicitly as addressing protocol. It is mostly
used with TCP. The IP addresses in packets help in routing them through different
nodes in a network until it reaches the destination system. TCP/IP is the most
popular protocol connecting the networks.

​ User Datagram Protocol (UDP):UDP is a substitute communication protocol to
Transmission Control Protocol implemented primarily for creating loss-tolerating
and low-latency linking between different applications

​ Post office Protocol (POP): POP3 is designed for receiving incoming E-mails.

​ Simple mail transport Protocol (SMTP): SMTP is designed to send and distribute
outgoing E-Mail.

​ File Transfer Protocol (FTP): FTP allows users to transfer files from one machine to
another. Types of files may include program files, multimedia files, text files, and
documents, etc.

​ Hyper Text Transfer Protocol (HTTP): HTTP is designed for transferring a
hypertext among two or more systems. HTML tags are used for creating links.
These links may be in any form like text or images. HTTP is designed on
Client-server principles which allow a client system for establishing a connection
with the server machine for making a request. The server acknowledges the request
initiated by the client and responds accordingly.

​ Hyper Text Transfer Protocol Secure (HTTPS):: HTTPS is abbreviated as Hyper
Text Transfer Protocol Secure is a standard protocol to secure the communication
among two computers one using the browser and other fetching data from web
server. HTTP is used for transferring data between the client browser (request) and
the web server (response) in the hypertext format, same in case of HTTPS except
that the transferring of data is done in an encrypted format. So it can be said that
https thwart hackers from interpretation or modification of data throughout the
transfer of packets.

​ Telnet:Telnet is a set of rules designed for connecting one system with another. The
connecting process here is termed as remote login.
​ Remote access protocol.
​ Protocol to creating a connection with remote machine over network.

​ Gopher:Gopher is a collection of rules implemented for searching, retrieving as well
as displaying documents from isolated sites
​ It is global traking device.

Functions of web server:


1. Stores and secures website data:

In web hosting services, a web server stores all website data and secures it from unauthorized
users when it is properly configured

2. Provides web database access:

A web server’s responsibility is to provide access to websites that are hosted

3. Serve the end user requests:

Web servers accept requests from different users connected over the internet and serve them
accordingly.

4. Bandwidth controlling to regulate network traffic:

It is a feature available in web server to minimize excess network traffic.

Static Web page


Static web pages are also known as flat or stationary web page.They are loaded on the
client’s browser as exactly they are stored on the web server. Such web pages contain only
static information. User can only read the information but can’t do any modification or
interact with the information.

Dynamic Web page

Dynamic web page shows different information at different point of time. It is possible to
change a portaion of a web page without loading the entire web page. It has been made
possible using Ajax technology.

Dynamic Content

Any content on your webpages that is subject to change, is classified as dynamic content.The
content of a website that does not remain constant and changes according to user input(s) is
referred to as dynamic content. For instance, in case of a product page, all product details
such as Product Name, Price, Quantity, and Description are stored in a database and are
fetched when a user is viewing the webpage of a particular product.

Dynamic content creates better shopping experiences.


Dynamic content is a web-page or email component that changes. Typically, changes are
based on user signals that include in-session behavior, user data, and user-characteristics.

In-session behavior- Adapt content based on what pages they visit, which products they add
to cart, and how long they spend on site.

User data - Change content based on past purchases, customer lifecycle, or past engagements
with your marketing

User Characteristics - Adapt content based on demographics such as geo-location .

Benefits of Dynamic Content


Increased Relevancy - Customers judge your webpage in less than a second.
Increased personalizable: Every single response can be crafted based on user request.

It is interactive: Dynamic website a two way communication they provide content to users
and they allow user to submit information back to server .
Different step in creating the Dynamic content

1. You enter http://server.com into your browser’s address bar.


2. Your browser looks up the IP address for server.com.
3. Your browser issues a request for the home page at server.com.
4. The request crosses the Internet and arrives at the server.com web server.
5. The web server, having received the request, looks for the web page on its hard disk.
6. The web page is retrieved by the server and returned to the browser.
7. Your browser displays the web page.

In step 2 the browser consults an additional Internet service called the Domain Name Service
(DNS) to find its associated IP address and then uses it to communicate with the computer.

For dynamic web pages, the procedure is a little more involved, because it may bring both
PHP and MySQL into the mix:
Here are the steps for a dynamic client/server request/response sequence:

1. You enter http://server.com into your browser’s address bar.


2. Your browser looks up the IP address for server.com.
3. Your browser issues a request to that address for the web server’s home page.
4. The request crosses the Internet and arrives at the server.com web server.
5. The web server, having received the request, fetches the home page from its hard disk.
6. With the home page now in memory, the web server notices that it is a file
incorporating PHP scripting and passes the page to the PHP interpreter.
7. The PHP interpreter executes the PHP code.
8. Some of the PHP contains MySQL statements, which the PHP interpreter now passes
to the MySQL database engine.
9. The MySQL database returns the results of the statements back to the PHP interpreter.
10. The PHP interpreter returns the results of the executed PHP code, along with the
results from the MySQL database, to the web server.
11. The web server returns the page to the requesting client, which displays it.

PHP - Error & Exception Handling

Error handling is the process of catching errors raised by our program and then taking
appropriate action.
These are functions dealing with error handling and logging. They allow you to define your
own error handling rules, as well as modify the way the errors can be logged. This allows you
to change and enhance error reporting to suit your needs.

When function return FALSE,we can use the die function in php to print an error message.
When php call die function,the application quits.
die(“message”)
1.
2. <?php
3.
4. // Php code showing default error handling
5.
6. $file = fopen("geeks.txt", "w");
7. ?>
Run the above code and geeks.txt file is not present then it will display an run-time
error message.
<?php

// PHP code to check errors

// If file is not present


// then exit from script
if( !file_exists("geeks.txt") ) {
die("File is not present");
}

// If file is present
// then continue
else {
$file = fopen("geeks.txt", "w");
}
?>

If geeks.txt file not present then it will display output.


Output

File is not present

What is cookie?
A cookie is a small piece of text file stored on user's computer in the form of name-value pair.
Cookies are used by websites to keep track of visitors e.g. to keep user information like
username etc. If any web application using cookies, Server send cookies and client browser will
store it. The browser then returns the cookie to the server at the next time the page is requested.
The most common example of using a cookie is to store User information, User preferences,
Password Remember Option etc

Advantages of using cookies


· Cookies are simple to use and implement.
· Occupies less memory, do not require any server resources and are stored on the user's
computer so no extra burden on server.
· We can configure cookies to expire when the browser session ends (session cookies) or
they can exist for a specified length of time on the client’s computer (persistent cookies).
· Cookies persist a much longer period of time than Session state.

Disadvantages of using cookies


· As mentioned previously, cookies are not secure as they are stored in clear text they may
pose a possible security risk as anyone can open and tamper with cookies. You can manually
encrypt and decrypt cookies, but it requires extra coding and can affect application
performance because of the time that is required for encryption and decryption
· Several limitations exist on the size of the cookie text(4kb in general), number of
cookies(20 per site in general), etc.
· User has the option of disabling cookies on his computer from browser’s setting .
· Cookies will not work if the security level is set to high in the browser.
· Users can delete a cookies.
· Users browser can refuse cookies,so your code has to anticipate that possibility.
· Complex type of data not allowed (e.g. dataset etc). It allows only plain text (i.e. cookie
allows only string content)
SESSION
A session is a global variable stored on the server.
Each session is assigned a unique id which is used to retrieve stored values.
Whenever a session is created, a cookie containing the unique session id is stored on the
user’s computer and returned with every request to the server. If the client browser does not
support cookies, the unique php session id is displayed in the URL.
Sessions have the capacity to store relatively large data compared to cookies
In order to create a session, you must first call the PHP session_start function
Advantages:
Session provide us the way of maintain user state/data.
It is very easy to implement.
One big advantage of session is that we can store any kind of object in it. :eg, datatabe,
dataset.. etc
By using session we don't need to worry about data collesp, because it store every client data
separately.
Session is secure and transparent from the user.
Disadvantages:
Performance overhead in case of large volumes of data/user, because session data is stored in
server memory.

SESSION vs COOKIE

● Cookies are small files saved on the user’s computer


● Cookies can only be read from the issuing domain
● Cookies can have an expiry time, if it is not set, then the cookie expires when the
browser is closed
● Sessions are like global variables stored on the server
● Each session is given a unique identification id that is used to track the variables for a
user.
● Both cookies and sessions must be started before any HTML tags have been sent to
the browser.

EXCEPTION HANDLING IN PHP:

An exception is a generalization of the concept of an error to include any unexpected


condition encountered during execution.

Exception handling is used to change the normal flow of the code execution if a
specified error (exceptional) condition occurs. This condition is called an exception.

It can be handled by

Try:A function using an exception should be in a "try" block. If the exception does
not trigger, the code will continue as normal. However if the exception triggers, an
exception is "thrown".

Catch: It represent block of code that will be executed when a particular exception has
been thrown.

Finally:It is used in place of catch block or after catch block basically it is put for
cleanup activity in PHP code.

Throw :It is used to throw an exception. It is also used to list the exceptions that a
function throws, but doesn’t handle itself.

Each try must have a atleast one corresponding catch or finally block.
Code within the finally block will always be executed after the try and catch

Block,regardless of whether an exception has been thrown, and before normal


execution resumes.

If an exception is not caught ,a fatal error will isused with uncaught exception
message.

For eg

<?php
$a =11;
try{
if ($a>=10) {

echo "$a";
}
else {
throw new Exception("Enter value greater than 10");

}
}

catch(Exception $e)// exception objet.


{
echo $e->getMessage();
}
finally
{
echo "</br>finally Block";
}
?>

Why Exception Handling in PHP ?

Following are the main advantages of exception handling over error handling

● Separation of error handling code from normal code: In traditional error


handling code there is always if else block to handle errors. These
conditions and code to handle errors got mixed so that becomes
unreadable. With try Catch block code becomes readable.
● Grouping of error types: In PHP both basic types and objects can be
thrown as exception. It can create a hierarchy of exception objects, group
exceptions in namespaces or classes, categorize them according to
types.

You might also like