Information Technology

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 81

InformatioTechnology

Q1) Internet , Extranet ,Intranet.

Ans :- 1. Internet :
The network formed by the co-operative interconnection of millions of
computers, linked together is called Internet. Internet comprises of :
 People : People use and develop the network.
 Resources : A collection of resources that can be reached from those
networks.
 A setup for collaboration : It includes the member of the research and
educational committees worldwide.

2. Intranet :
It is an internal private network built within an organization using Internet and
World Wide Web standards and products that allows employees of an
organization to gain access to corporate information.

3. Extranet :
It is the type of network that allows users from outside to access the Intranet
of an organization.
Difference between Internet, Intranet and Extranet :
Point of
difference Internet Intranet Extranet

Accessibility
Public Private Private
of network

To share information
Specific to an with suppliers and
Availability Global system.
organization. vendors it makes the
use of public network.

Restricted area upto an


All over the Restricted area upto organization and some
Coverage
world. an organization. of its stakeholders or
so.
Point of
difference Internet Intranet Extranet

Accessible only to the


It is accessible to It is accessible only to members of
Accessibility
everyone the members of organization and
of content
connected. organization. external members with
logins.

It is largest in
No. of The minimal number The connected devices
number of
computers of devices are are more comparable
connected
connected connected. with Intranet.
devices.

Single/ Multiple
Owner No one. Single organization.
organization.

It’s purpose is to
It’s purpose is to It’s purpose is to share
share
Purpose of the share information information between
information
network throughout the members and external,
throughout the
organization. members.
world.

It is dependent
It is enforced via
on the user of the It is enforced via
Security firewall that separates
device connected firewall.
internet and extranet.
to network.

Employees of the
Employees of the
Users General public. organization which are
organization.
connected.

There is no hard Policies of the Policies of the


Policies
and fast rule for organization are organization are
behind setup
policies. imposed. imposed.

It is maintained by It is maintained by
CIO. HR or CIO. HR or
It is maintained
Maintenance communication communication
by ISP.
department of an department of an
organization. organization.
Point of
difference Internet Intranet Extranet

It is more
It is also less
Economical economical to It is less economical.
economical.
use.

It is the network It is derived from It is derived from


Relation
of networks. Internet. Intranet.

What we are WIPRO using internal DELL and Intel using


Example normally using is network for its network for its
internet. business operations. business operations.

Q2) Domain And Sub-Domain

Ans:- Every computer on the Internet has an address which is unique in


nature. It is a string of numbers and is referred to as IP address. To
communicate with each other, computers identify another computer via its IP
address. It is represented in either dotted decimal notation or in binary
decimal notation. Example: The address 172.16.122.204 when represented
like these in dotted-decimal notation and it can be converted into binary
notation. After conversion, it becomes 10101100 00010000 01111010
11001100.

But it is difficult for humans to remember this IP address. Thus to find the
location on the Internet easily, DNS was invented. DNS stands for Domain
Name Server. It implements a distributed database which translates IP
address into a unique alphanumeric address which is referred to as Domain
Names. Basically, a domain name is the sequence of letters and or numbers
separated by one or more period (“.”). It is just like a pointer to a unique IP
address on the computer network. As an analogy one can consider Domain
name as address and DNS as address book of the Internet.
Example-1:
Lets us consider an example for domain name;
www.google.com, www.yahoo.com
In this “yahoo.com” is called domain name.
“www.” tells the browser to look for World Wide Web Interface for that
domain.
As from the above example, it is clear that domain names are easy to
remember than an IP address.
Example-2:
Assume that the IP address of www.yahoo.com is 69.147.76.15. It is easy to
remember www.yahoo.com as compared to IP address 69.147.76.15.
Thus, we can say like these; domain name refers to the string of letters
associated with an IP address and DNS is a mechanism used to convert an
IP address to the domain name.

Types of Domain Names :


DNS has organized all the domain names in a hierarchical structure. At the
top of this hierarchy come various Top-level domains followed by second and
third-level domains and sub-domains. All these types of domain names are
listed as follows –
Top Level Domains (TLD) :
The Top Level Domains are at the highest level in DNS structure of the
Internet. It is sometimes also referred to as an extension. It is further
categorized into- country code TLDs and generic TLDs which Country is
described as follows –
 Country code Top Level Domain (ccDLDs) :
It consists of two-letter domains that include one entry for every country.
Example – .in for India, .au for Australia, .us for United Nations, .jp for
Japan etc. To target the local audience it is used by companies and
organizations . Only the residents of the country are allowed to is their
specified ccTLD but now some countries allowed the users outside their
country to register their corresponding ccTLDs.
 Generic Top Level Domains (gTLDs) :
These are open for registration to all the users regardless of their
citizenship, residence or age. Some of the gTLD s are .com for
commercial sites, .net for network companies, .biz for business, .org for
organizations, .edu for education.
There are various other levels which are below TLDs –
Second Level :
It is just below the TLD in the DNS hierarchy. It is also named as the label.
Example: in .co.in, .co is the second-level domain under the .in in ccTLD.
Third Level :
It is directly below the second level. Example: in yahoo.co.in, .yahoo is the
third level domain under the second level domain .co which is under the .in
ccTLD.
Sub-domain :
It is the part of a higher domain name in DNS hierarchy. Example:
yahoo.com comprises a subdomain of the .com domain, and
login.yahoo.com comprises a subdomain of the domain .yahoo.com.
Advantages of Domain Name :
 User not need to remember the IP address.
 More reliable and secure.
Disadvantages of Domain Name :
 IP address changes due to several reasons, due to this IP address of the
computer get changed but DNS may have cached previous IP which will
lead to give us wrong information.

Q3) DNS (Domain Name System)


o Ans:- DNS stands for Domain Name System.
o DNS is a directory service that provides a mapping between the name of a
host on the network and its numerical address.
o DNS is required for the functioning of the internet.
o Each node in a tree has a domain name, and a full domain name is a sequence
of symbols specified by dots.
o DNS is a service that translates the domain name into IP addresses. This allows
the users of networks to utilize user-friendly names when looking for other
hosts instead of remembering the IP addresses.
o For example, suppose the FTP site at EduSoft had an IP address of
132.147.165.50, most people would reach this site by specifying
ftp.EduSoft.com. Therefore, the domain name is more reliable than IP address.

DNS is a TCP/IP protocol used on different platforms. The domain name space is
divided into three different sections: generic domains, country domains, and inverse
domain.
Generic Domains
o It defines the registered hosts according to their generic behavior.
o Each node in a tree defines the domain name, which is an index to the DNS
database.
o It uses three-character labels, and these labels describe the organization type.
o (diagrm –nxt pge)
o Country Domain
o The format of country domain is same as a generic domain, but it uses two-
character country abbreviations (e.g., us for the United States) in place of
three character organizational abbreviations.
o Inverse Domain
o The inverse domain is used for mapping an address to a name. When the
server has received a request from the client, and the server contains the files
of only authorized clients. To determine whether the client is on the
authorized list or not, it sends a query to the DNS server and ask for mapping
an address to the name.
o

Q4) Three-Way Handshaking,

Ans :- TCP Connection (A 3-way handshake)


Handshake refers to the process to establish connection between the client and
server. Handshake is simply defined as the process to establish a communication link.
To transmit a packet, TCP needs a three way handshake before it starts sending data.
The reliable communication in TCP is termed as PAR (Positive Acknowledgement Re-
transmission). When a sender sends the data to the receiver, it requires a positive
acknowledgement from the receiver confirming the arrival of data. If the
acknowledgement has not reached the sender, it needs to resend that data. The
positive acknowledgement from the receiver establishes a successful connection.

Here, the server is the server and client is the receiver. The above diagram shows 3
steps for successful connection. A 3-way handshake is commonly known as SYN-
SYN-ACK and requires both the client and server response to exchange the data. SYN
means synchronize Sequence Number and ACK means acknowledgment. Each
step is a type of handshake between the sender and the receiver.

The diagram of a successful TCP connection showing the three handshakes is shown
below:

The three handshakes are discussed in the below steps:

Step 1: SYN
SYN is a segment sent by the client to the server. It acts as a connection
request between the client and server. It informs the server that the client wants to
establish a connection. Synchronizing sequence numbers also helps synchronize
sequence numbers sent between any two devices, where the same SYN segment asks
for the sequence number with the connection request.

Step 2: SYN-ACK
It is an SYN-ACK segment or an SYN + ACK segment sent by the server. The ACK
segment informs the client that the server has received the connection request and it
is ready to build the connection. The SYN segment informs the sequence number
with which the server is ready to start with the segments.

Step 3: ACK
ACK (Acknowledgment) is the last step before establishing a successful TCP
connection between the client and server. The ACK segment is sent by the client as
the response of the received ACK and SN from the server. It results in the
establishment of a reliable data connection.
After these three steps, the client and server are ready for the data communication
process. TCP connection and termination are full-duplex, which means that the data
can travel in both the directions simultaneously.

TCP Termination (A 4-way handshake)


Any device establishes a connection before proceeding with the termination. TCP
requires 3-way handshake to establish a connection between the client and server
before sending the data. Similarly, to terminate or stop the data transmission, it
requires a 4-way handshake. The segments required for TCP termination are similar
to the segments to build a TCP connection (ACK and SYN) except the FIN segment.
The FIN segment specifies a termination request sent by one device to the other.

The client is the data transmitter and the server is a receiver in a data transmission
process between the sender and receiver. Consider the below TCP termination
diagram that shows the exchange of segments between the client and server.

The diagram of a successful TCP termination showing the four handshakes is shown
below:

Let's discuss the TCP termination process with the help of six steps that includes the
sent requests and the waiting states. The steps are as follows:

Step 1: FIN
FIN refers to the termination request sent by the client to the server. The first FIN
termination request is sent by the client to the server. It depicts the start of the
termination process between the client and server.
Step 2: FIN_ACK_WAIT
The client waits for the ACK of the FIN termination request from the server. It is
a waiting state for the client.

Step 3: ACK
The server sends the ACK (Acknowledgement) segment when it receives the FIN
termination request. It depicts that the server is ready to close and terminate the
connection.

Step 4: FIN _WAIT_2


The client waits for the FIN segment from the server. It is a type of approved signal
sent by the server that shows that the server is ready to terminate the connection.

Step 5: FIN
The FIN segment is now sent by the server to the client. It is a confirmation signal
that the server sends to the client. It depicts the successful approval for the
termination.

Step 6: ACK
The client now sends the ACK (Acknowledgement) segment to the server that it has
received the FIN signal, which is a signal from the server to terminate the connection.
As soon as the server receives the ACK segment, it terminates the connection.

Q5) TELNET –

It provides bi-directional text-oriented services for remote login to the hosts over the
network. TELNET (Terminal Network):

• TELNET is client-server application that allows a user to log onto remote machine and lets
the user to access any application program on a remote computer.

• TELNET uses the NVT (Network Virtual Terminal) system to encode characters on the
local system.

• On the server (remote) machine, NVT decodes the characters to a form acceptable to the
remote machine.

• TELNET is a protocol that provides a general, bi-directional, eight-bit byte oriented


communications facility.
• Many application protocols are built upon the TELNET protocol
• Telnet services are used on PORT 23.
 FTP:

File Transfer Protocol, FTP − It is a client-server based protocol for transfer of files between
client and server over the network.
• File Transfer Protocol (FTP) is the standard mechanism provided by TCP/IP for copying a
file from one host to another.
• FTP establishes two connections between the hosts
• One connection is used for data transfer, the other for control information (commands and
responses)
• Separation of commands and data transfer makes FTP more efficient
• FTP uses two well-known TCP ports: Port 21 is used for the control connection, and port 20
is used for the data connection.

 HTTP
o Hyper Text Transfer Protocol, HTTP − It is the underlying protocol for world
wide web. It defines how hypermedia messages are formatted and
transmitted.
o It is a protocol used to access the data on the World Wide Web (www).
o The HTTP protocol can be used to transfer the data in the form of plain text,
hypertext, audio, video, and so on.
o This protocol is known as HyperText Transfer Protocol because of its efficiency
that allows us to use in a hypertext environment where there are rapid jumps
from one document to another document.
o HTTP is similar to the FTP as it also transfers the files from one host to another
host. But, HTTP is simpler than FTP as HTTP uses only one connection, i.e., no
control connection to transfer the files.
o HTTP uses the services of TCP on well-known port 80.
o Accessing of web page is based on URL
o HTTP is similar to SMTP as the data is transferred between client and server.
The HTTP differs from the SMTP in the way the messages are sent from the
client to the server and from server to the client. SMTP messages are stored
and forwarded while HTTP messages are delivered immediately.

Q6)

Ans:- Routing is the process of selecting a path for traffic in a network or between or
across multiple networks. Broadly, routing is performed in many types of networks,
including circuit-switched networks, such as the public switched telephone network,
and computer networks, such as the Internet.
Interdomain Routing

Interdomain Routing is the protocol in which the routing algorithm works both within and
between domains. Domains must be connected in some way, for hosts inside one domain to
exchange data with hosts in other domains. This connection within domains is governed by
the interdomain routing protocols. This is often done using the Border Gateway Protocol
(BGP). It is used in Path Vector Routing using which interdomain routing is performed.
In path vector routing, the routing depends on the analysis of the path from the nodes in the
current domain to the node in the other domain, and not on the distance between nodes.

Intradomain Routing

Intradomain Routing is the routing protocol that operates only within a domain. In other
words, intradomain routing protocols are used to route packets within a specific domain, such
as within an institutional network for e-mail or web browsing. Unlike interdomain routing
protocols, it doesn't communicate with other domains. There are two types of protocols used
for intradomain routing:

1. Distance Vector Routing (uses Routing Information Protocol or RIP) In distance


vector routing, each node in a domain stores information about its neighboring nodes.
The information is stored in a table known as a routing table, which is maintained by
each node in the domain. RIP is one of the earliest distance-vector routing protocols,
and it uses hop count as a routing statistic. By placing a cap on the maximum number
of hops that may be taken between a source and a destination, RIP avoids routing
loops.

2. Link State Routing (uses Open Shortest Path First or OSPF) In link state routing,
each node in a domain stores information about all the other nodes in the domain, in
other words, the routing table of each node stores information about the entire
topology of the domain. Since each node has all the information about the domain at
its disposal, Dijkstra's algorithm is used to calculate the best routing path. This is
possible due to OSPF, and this is also its advantage.

Q7) Unicast and Multicast Routing, Broadcast


Ans:-

Unicast:

This type of information transfer is useful when there is a participation of a


single sender and a single recipient. So, in short, you can term it a one-to-
one transmission. For example, if a device having IP address 10.1.2.0 in a
network wants to send the traffic stream(data packets) to the device with IP
address 20.12.4.2 in the other network, then unicast comes into the picture.
This is the most common form of data transfer over networks.
Broadcast:

In Broadcast transmission, the data is transmitted from one or more


senders to all the receivers within the same network or in other networks.
This type of transmission is useful in network management packets such
as ARP (Address Resolution Protocol) and RIP (Routing Information
Protocol) where all the devices must see the data.

Broadcasting transfer (one-to-all) techniques can be classified into two types:

Limited Broadcasting: In Limited Broadcast, the data is transmitted from a


single source host to all the other hosts residing in the same network.
Direct Broadcasting: Directed Broadcast transmits data from one source
host to all the other hosts that exist in some other network. It is used in two
scenarios −

 When the hosts are responsible for parsing data from broadcast packets.
 When all the hosts require the same data.

Multicast Transmission (One-to-Many)


When the data is transmitted from a single source host to a specific group of
hosts having the interest to receive the data, it is known as multicast
transmission. Multicast can be more efficient than unicast when different
groups of receivers need to see the same data.

Example − Multicast is the technique used in Internet streaming of video or


audio teleconference, sending an email to a particular group of people, etc.

 Difference between Unicast and Multicast :


S.No
. Unicast Multicast

It has one sender and one It has one or more senders and
1. receiver. multiple receivers.

It sends data from one device to It sends data from one device to
2. single device. multiple devices.

It works on Single Node It works on star, mesh, tree and


3. Topology. hybrid topology.
It does not scale well for It does not scale well across large
4. streaming media. networks.

Multiple unicasting utilizes


5. more bandwidth as compared. It utilizes bandwidth efficiently.

Web surfing, file transfer is an Video Streaming,Online gaming is an


6. example of a unicast. example of a multicast .

7. It has one-to-one mapping. It has one-to-many mapping.

8. Network traffic is high. Network traffic is low.

9. Mobile is a unicast device. Switch is a multicast device.

 Difference between Unicast and Multicast :


S.No
. Unicast Multicast

It has one sender and one It has one or more senders and
1. receiver. multiple receivers.

It sends data from one device to It sends data from one device to
2. single device. multiple devices.

It works on Single Node It works on star, mesh, tree and


3. Topology. hybrid topology.

It does not scale well for It does not scale well across large
4. streaming media. networks.

Multiple unicasting utilizes


5. more bandwidth as compared. It utilizes bandwidth efficiently.

Web surfing, file transfer is an Video Streaming,Online gaming is an


6. example of a unicast. example of a multicast .

7. It has one-to-one mapping. It has one-to-many mapping.

8. Network traffic is high. Network traffic is low.

9. Mobile is a unicast device. Switch is a multicast device.


Q. E-mail

• Electronic mail, or more commonly email, used to communicate with different users in
internet
• Email uses following protocols for storing & delivering messages, They are :
1. SMTP (Simple Mail Transfer Protocol)
2. POP (Post Office Protocol)
3. IMAP (Internet Message Access Protocol)

• Email consists of two kinds of subsystems


1. Mail User Agents (also called MUA/email client programs): which allow people to read
and send email (Ex: Outlook)
2. Message Transfer Agents(also called MTA/ Email Server) : which move the messages
from the source to the destination (Ex: Gmail Server)
• Act of sending new messages into the mail system for delivery is called Mail submission
(Email Client to Email Sever)
• The Process of transferring mail from one MTA to another (Ex : from gmail to yahoo
server) is called Message Transfer
• Mailboxes store the email that is received for a user (Working all Protocols).

Q8) What is IPv4?


IPv4 is an IP version widely used to identify devices on a network
using an addressing system. It was the first version of IP deployed
for production in the ARPANET in 1983. It uses a 32-bit address
scheme to store 2^32 addresses which is more than 4 billion
addresses. It is considered the primary Internet Protocol and carries
94% of Internet traffic.

What is IPv6?
IPv6 is the most recent version of the Internet Protocol. This new IP
address version is being deployed to fulfill the need for more
Internet addresses. It was aimed to resolve issues that are
associated with IPv4. With 128-bit address space, it allows 340
undecillion unique address space. IPv6 is also called IPng (Internet
Protocol next generation).
Internet Engineer Taskforce initiated it in early 1994. The design
and development of that suite are now called IPv6.
IPv4 ADDRESSING SCHEME
IP addresses falls into two types:
• Classful IP addressing is a legacy scheme which divides the whole IP address pools
into 5 distinct
classes—A, B, C, D and E.

• Classless IP addressing has an arbitrary length of the prefixes.

Classful Addressing :
Class A
The first octet denotes the network address, and the last three octets are the host
portion. Any IP address whose first octet is between 1 and 126 is a Class A address.
Note that 0 is reserved as a part of the default address and 127 is reserved for internal
loopback testing.
Format: network.host.host.host
Default subnet mask = 255.0.0.0 or (slash notation) /8

Class B

The first two octets denote the network address, and the last two octets are the host
portion. Any address whose first octet is in the range 128 to 191 is a Class B address.
Format: network.network.host.host
Default subnet mask =255.255.0.0 or /16

Class C
The first three octets denote the network address, and the last octet is the host portion.
The first octet range of 192 to 223 is a Class C address.
Format: network.network.network.host
Default subnet mask = 255.255.255.0 or /24

Class D
Used for multicast. Multicast IP addresses have their first octets in the range 224 to 239.

Class E
Reserved for future use or research purpose and includes the range of addresses with a
first octet from
240 to 255.

The major differences between IPv4 and IPv6 are:

IPv4 (Internet Protocol Version 4) IPv6 (Internet Protocol Version 6)

Encryption and authentication is not provided in IPv4 Encryption and authentication is provided in
(Internet Protocol Version 4). IPv6 (Internet Protocol Version 6)

Header of IPv4 is 20 – 60 bytes. Header of IPv6 is fixed at 40 bytes

Checksumfield is available in IPv4. Checksumfield is not available in IPv6.


Packet flow identification is not available in IPv4 (Internet Packet flow identification is available in IPv6.
Protocol Version 4). Flow label field is available in the header.

IPv4 addresses are usually represented in dot-decimal An IPv6 address is represented as eight
notation, consisting of four decimal numbers, each groups of four hexadecimal digits, each
ranging from 0 to 255, separated by dots. group representing 16 bits.

Sender and forwarding routers performs fragmentation in Fragmentation is performed only by the
IPv4 sender in IPv6.

In IPv4, security features relies on application In IPv6, there is an inbuilt security feature
named IPSEC.

End to end connection integrity cannot be achieved in End to end connection integrity can be done
IPv4. in IPv6.

IPv4 supports DHCP and Manual address configuration IPv6 supports renumbering and auto
address configuration.

IPv4 addresses are 32-bit long IPv6 addresses are 128 bits long.

The address space in IPv4 is 4.29 ×109 The address space in IPv6 is 3.4 ×1038

IPv4 has a broadcast message transmission scheme. Multicast and Anycast message transmission
scheme is available in IPv6.

 Subnetting : - When a bigger network is divided into smaller networks,


to maintain security, then that is known as Subnetting. So,
maintenance is easier for smaller networks. For example, if we
consider a class A address, the possible number of hosts is 224 for
each network, it is obvious that it is difficult to maintain such a huge
number of hosts, but it would be quite easier to maintain if we divide
the network into small parts.
Advantages of Subnetting
The advantages of Subnetting are mentioned below:
1. It provides security to one network from another network. eg) In an
Organisation, the code of the Developer department must not be
accessed by another department.
2. It may be possible that a particular subnet might need higher network
priority than others. For example, a Sales department needs to host
webcasts or video conferences.
3. In the case of Small networks, maintenance is easy.
Disadvantages of Subnetting
The disadvantages of Subnetting are mentioned below:
1. In the case of a single network, only three steps are required to reach a
Process i.e Source Host to Destination Network, Destination Network to
Destination Host, and then Destination Host to Process.
2. In the case of a Single Network only two IP addresses are wasted to
represent Network Id and Broadcast address but in the case of
Subnetting two IP addresses are wasted for each Subnet.
3. The cost of the overall Network also increases. Subnetting requires
internal routers, Switches, Hubs, Bridges, etc. which are very costly.

Q9) Congestion Control in Computer Networks

What is congestion?
A state occurring in network layer when the message traffic is so heavy that it slows
down network response time.

Effects of Congestion
 As delay increases, performance decreases.
 If delay increases, retransmission occurs, making situation worse.

Congestion control algorithms


 Congestion Control is a mechanism that controls the entry of data packets into the
network, enabling a better use of a shared network infrastructure and avoiding
congestive collapse.
 Congestive-Avoidance Algorithms (CAA) are implemented at the TCP layer as the
mechanism to avoid congestive collapse in a network.
 There are two congestion control algorithm which are as follows:

 Leaky Bucket Algorithm


 The leaky bucket algorithm discovers its use in the context of network traffic
shaping or rate-limiting.
 A leaky bucket execution and a token bucket execution are predominantly used for
traffic shaping algorithms.
 This algorithm is used to control the rate at which traffic is sent to the network and
shape the burst traffic to a steady traffic stream.
 The disadvantages compared with the leaky-bucket algorithm are the inefficient
use of available network resources.
 The large area of network resources such as bandwidth is not being used
effectively.

Let us consider an example to understand

Imagine a bucket with a small hole in the bottom.No matter at what rate water enters
the bucket, the outflow is at constant rate.When the bucket is full with water
additional water entering spills over the sides and is lost.

Similarly, each network interface contains a leaky bucket and the following steps are
involved in leaky bucket algorithm:
1. When host wants to send packet, packet is thrown into the bucket.
2. The bucket leaks at a constant rate, meaning the network interface transmits
packets at a constant rate.
3. Bursty traffic is converted to a uniform traffic by the leaky bucket.
4. In practice the bucket is a finite queue that outputs at a finite rate.

 Token bucket Algorithm


 The leaky bucket algorithm has a rigid output design at an average rate
independent of the bursty traffic.
 In some applications, when large bursts arrive, the output is allowed to speed up.
This calls for a more flexible algorithm, preferably one that never loses
information. Therefore, a token bucket algorithm finds its uses in network traffic
shaping or rate-limiting.
 It is a control algorithm that indicates when traffic should be sent. This order
comes based on the display of tokens in the bucket.
 The bucket contains tokens. Each of the tokens defines a packet of predetermined
size. Tokens in the bucket are deleted for the ability to share a packet.
 When tokens are shown, a flow to transmit traffic appears in the display of tokens.
 No token means no flow sends its packets. Hence, a flow transfers traffic up to its
peak burst rate in good tokens in the bucket.

Need of token bucket Algorithm:-

The leaky bucket algorithm enforces output pattern at the average rate, no matter how
bursty the traffic is. So in order to deal with the bursty traffic we need a flexible
algorithm so that the data is not lost. One such algorithm is token bucket algorithm.

Steps of this algorithm can be described as follows :

1. In regular intervals tokens are thrown into the bucket. ƒ


2. The bucket has a maximum capacity. ƒ
3. If there is a ready packet, a token is removed from the bucket, and the packet is
sent.
4. If there is no token in the bucket, the packet cannot be sent.

Let’s understand with an example,


In figure (A) we see a bucket holding three tokens, with five packets waiting to be
transmitted. For a packet to be transmitted, it must capture and destroy one token. In
figure (B) We see that three of the five packets have gotten through, but the other two
are stuck waiting for more tokens to be generated.

Ways in which token bucket is superior to leaky bucket: The leaky bucket
algorithm controls the rate at which the packets are introduced in the network, but it is
very conservative in nature. Some flexibility is introduced in the token bucket
algorithm. In the token bucket, algorithm tokens are generated at each tick (up to a
certain limit). For an incoming packet to be transmitted, it must capture a token and
the transmission takes place at the same rate. Hence some of the busty packets are
transmitted at the same rate if tokens are available and thus introduces some amount
of flexibility in the system.

Formula: M * s = C + ? * s where S – is time taken M – Maximum output rate ? –


Token arrival rate C – Capacity of the token bucket in byte

o Some advantage of token Bucket over leaky bucket –

• If bucket is full in token Bucket , tokens are discard not packets. While in leaky bucket,
packets are
discarded.
• Token Bucket can send Large bursts at a faster rate while leaky bucket always sends
packets at constant rate.
Security Issues
Network security is now of the utmost importance in today's environment, when
practically everything is connected via networks. Cyberattacks are a persistent threat
to networks, and the results can be disastrous. Network breaches can seriously harm
both people and organizations through identity theft and financial losses. To ensure
network security, there are a number of protective techniques that can be applied.

1. Firewalls: The first line of protection against network threats is the firewall. A
firewall is a network security device that monitors and restricts network traffic
based on predefined security rules. Firewalls, which may be deployed as
hardware or software, can prevent illegal network access.
2. Virtual Private Networks (VPNs): VPNs enable secure network access
through the internet. VPNs utilize encryption to safeguard data sent over the
network, making it more difficult for attackers to intercept and steal data.
VPNs are especially beneficial for distant workers who need to access the
network from locations other than the office.
3. Intrusion Detection and Prevention Systems (IDPS): IDPSs are intended to
identify and prevent network assaults. To identify and prevent suspect
network traffic, they employ a variety of approaches such as signature-based
detection, anomaly detection, and heuristic analysis. IDPSs can also be
programmed to respond to assaults automatically by restricting traffic or
shutting down vulnerable services.
4. Antivirus and Anti-Malware Software: Antivirus and anti-malware software
are critical for keeping viruses and other harmful software out of the network.
These applications monitor incoming and outgoing data for known risks and
prevent them from causing harm. Antivirus software should be updated on a
regular basis to guarantee that it can detect the most recent threats.
5. Patch Management: Keeping all software up to date is critical for network
security. Many software updates include security patches that fix
vulnerabilities that can be exploited by attackers. Regularly applying these
patches can prevent attackers from exploiting known vulnerabilities.
6. Access Controls: Access restrictions are used to limit network access to only
authorized users. Passwords, biometric authentication, and other
authentication techniques can be used to accomplish this. Access restrictions
should be evaluated and modified on a regular basis to ensure that only
authorized users have access to the network.
7. Employee Education and Training: Staff education and training are critical to
network security. Workers should be educated on the necessity of network
security and the dangers of network breaches. They should also be taught
how to detect and respond to questionable network behavior.

Finally, both people and companies must defend their networks against cyberattacks.
Applying the aforementioned security measures can assist to guarantee network
security. It's vital to remember that network security is a never-ending process that
requires ongoing monitoring and tweaking to stay up with new threats.

 Password and Authentication,

Password and authentication are fundamental components of security


systems, playing a critical role in verifying the identity of users and
protecting sensitive information. Here are key considerations and best
practices for managing passwords and authentication:

Password Best Practices:

1.Password Complexity:
- Encourage users to create strong passwords that include a mix of
uppercase and lowercase letters, numbers, and special characters.
- Avoid easily guessable information such as birthdays, names, or
common words.

2. Password Length:
- Longer passwords are generally more secure. Encourage the use of
passphrases that are both easy to remember and difficult to crack.

3. Password Rotation:
- Regularly prompt users to change their passwords, especially for
critical systems and sensitive accounts. However, avoid overly
frequent changes, as this can lead to weaker passwords.

4. Multi-Factor Authentication (MFA):


- Implement MFA to add an extra layer of security. This typically involves
something you know (password) and something you have (e.g., a code from a
mobile app or a hardware token).
5.Account Lockout Policies:
- Enforce account lockout policies to protect against brute force
attacks. After a certain number of unsuccessful login attempts,
temporarily lock the account.

6. Password Storage:
- Store passwords securely using strong encryption methods. Avoid
storing plaintext passwords, and consider using technologies like
salted hashes to enhance security.

7. Education and Training:


- Educate users about the importance of password security and the
risks associated with password reuse across multiple accounts.

### Authentication Best Practices:

1. Biometric Authentication:
- Implement biometric authentication methods (e.g., fingerprint,
facial recognition) for enhanced security and user convenience.

2. **Single Sign-On (SSO):**


- Use SSO to allow users to access multiple applications with a
single set of credentials. This can simplify user management and
improve security.

3. **Adaptive Authentication:**
- Implement adaptive authentication mechanisms that adjust the
level of authentication based on contextual factors such as device,
location, and user behavior.

4. **OAuth and OpenID Connect:**


- Consider using OAuth for authorization and OpenID
Connect for authentication, especially in web-based
applications.

5. Session Management:
- Implement secure session management to protect against
session hijacking and session fixation attacks.

6. **Tokenization:**
- Use tokenization to replace sensitive data (such as passwords)
with unique tokens, reducing the risk associated with storing and
transmitting sensitive information.

7. **Continuous Monitoring:**
- Continuously monitor user activities and behavior to detect
anomalies and potential unauthorized access.

8. **Risk-Based Authentication:**
- Assess the risk level associated with each authentication attempt
and adjust the level of scrutiny accordingly.

9. **Mobile Authentication:**
- Leverage mobile device capabilities for authentication, such as
push notifications or one-time passcodes sent via SMS or mobile
apps.

10. **Secure Communication Protocols:**


- Use secure communication protocols (e.g., HTTPS) to protect the
transmission of authentication credentials over the network.

By combining strong password practices with advanced


authentication methods, organizations can significantly enhance the
overall security of their systems and protect against unauthorized
access. Regularly reviewing and updating authentication mechanisms
in response to emerging threats is crucial to maintaining a robust
security posture.
 VPN (Virtual Private Network)

VPN stands for Virtual Private Network (VPN) that


allows a user to connect to a private network over the
Internet securely and privately. VPN creates an
encrypted connection that is called VPN tunnel and all
Internet traffic and communication is passed through
this secure tunnel.
OR;
A Virtual Private Network (VPN) is a technology that enables secure and
encrypted communication over an untrusted network, such as the internet.
VPNs are widely used to enhance privacy, security, and anonymity for users,

Virtual Private Network (VPN) is basically of 2 types:


1. Remote Access VPN:
Remote Access VPN permits a user to connect to a
private network and access all its services and
resources remotely. The connection between the user
and the private network occurs through the Internet
and the connection is secure and private. Remote Access
VPN is useful for home users and business users
both.
2. Site to Site VPN:
A Site-to-Site VPN is also called as Router-to-Router
VPN and is commonly used in the large companies.
Companies or organizations, with branch offices in
different locations, use Site-to-site VPN to connect the
network of one office location to the network at another
office location.
• Intranet based VPN: When several offices of the same
company are connected using Site-to-Site VPN type, it is
called as Intranet based VPN.
• Extranet based VPN: When companies use Site-to-
site VPN type to connect to the office of another
company, it is called as Extranet based VPN.

Types of Virtual Private Network (VPN) Protocols:


1. Internet Protocol Security (IPSec):
Internet Protocol Security, known as IPSec, is used to
secure Internet communication across an IP network.
IPSec secures Internet Protocol communication by
verifying the session and encrypts each data packet
during the connection.

IPSec runs in 2 modes:


• (i) Transport mode
• (ii) Tunneling mode
The work of transport mode is to encrypt the message in
the data packet and the tunneling mode encrypts the
whole data packet. IPSec can also be used with other
security protocols to improve the security
system.
2. Layer 2 Tunneling Protocol (L2TP):
L2TP or Layer 2 Tunneling Protocol is a tunnelling
protocol that is often combined with another VPN
security protocol like IPSec to establish a highly secure
VPN connection. L2TP generates a tunnel between two
L2TP connection points and IPSec protocol encrypts the
data and maintains secure communication between the
tunnel.

3. Point–to–Point Tunneling Protocol (PPTP):

PPTP or Point-to-Point Tunneling Protocol generates


a tunnel and confines the data packet. Point-to-
Point Protocol (PPP) is used to encrypt the data between
the connection. PPTP is one of the most widely used
VPN protocol and has been in use since the early release
of Windows. PPTP is also used on Mac and Linux apart
from Windows.

4. SSL and TLS:


SSL (Secure Sockets Layer) and TLS (Transport Layer
Security) generate a VPN connection where the
web browser acts as the client and user access is
prohibited to specific applications instead of entire
network. Online shopping websites commonly uses SSL
and TLS protocol. It is easy to switch to SSL by web
browsers and with almost no action required from the
user as web browsers come integrated with SSL and TLS.
SSL connections have “https” in the initial of the URL
instead of “http”.
5. OpenVPN:
OpenVPN is an open source VPN that is commonly
used for creating Point-to-Point and Site-to-Site
connections. It uses a traditional security protocol based
on SSL and TLS protocol.
6. Secure Shell (SSH):
Secure Shell or SSH generates the VPN tunnel through
which the data transfer occurs and also ensures
that the tunnel is encrypted. SSH connections are
generated by a SSH client and data is transferred from a
local port on to the remote server through the
encrypted tunnel.

Advantages of Using VPNs:


1. Security:
 VPNs provide a secure and encrypted connection, protecting data from
potential eavesdropping and unauthorized access.
2. Privacy:
 Users can browse the internet more privately as their IP addresses are masked
by the VPN server's address.
3. Anonymity:
 VPNs help users maintain a degree of anonymity by concealing their true
location and identity.
4. Bypassing Geographical Restrictions:
 Users can access content and services that may be restricted or geo-blocked
in their region by connecting to a VPN server in a different location.
5. Remote Access:
 Facilitates secure remote access to corporate networks, allowing employees to
work from anywhere while ensuring the confidentiality of data.
6. Public Wi-Fi Security:
 Protects users from potential security threats when using public Wi-Fi
networks by encrypting the data transmitted over the connection.

Firewall
A firewall is a network security device, either hardware
or software-based, which monitors all incoming
and outgoing traffic and based on a defined set of
security rules it accepts, rejects or drops that specific
traffic.
Accept : allow the traffic
Reject : block the traffic but reply with an “unreachable
error”
Drop : block the traffic with no reply
A firewall establishes a barrier between secured internal
networks and outside untrusted network, such
as the Internet.

A firewall is a network security device that


monitors incoming and outgoing network traffic
and permits or blocks data packets based on a set
of security rules. Its purpose is to establish a
barrier between your internal network and
incoming traffic from external sources (such as the
internet) in order to block malicious traffic like
viruses and hackers.

Types of Firewall
Firewalls are generally of two types: Host-based and
Network-based.
1. Host- based Firewalls : Host-based firewall is
installed on each network node which controls each
incoming and outgoing packet. It is a software
application or suite of applications, comes as a part of
the operating system. Host-based firewalls are needed
because network firewalls cannot provide protection
inside a trusted network. Host firewall protects each
host from attacks and unauthorized access.
2. Network-based Firewalls : Network firewall
function on network level. In other words, these
firewalls filter all incoming and outgoing traffic across
the network. It protects the internal network by filtering
the traffic using rules defined on the firewall. A
Network firewall might have two or more network
interface cards (NICs). A network-based firewall is
usually a dedicated system with proprietary software
installed.

Generation of Firewall

Firewalls can be categorized based on its


generation.
First Generation- Packet Filtering Firewall :
Packet filtering firewall is used to control network
access by monitoring outgoing and incoming
packet and allowing them to pass or stop based on
source and destination IP
address, protocols and ports. It analyses traffic at the
transport protocol layer (but mainly uses first 3 layers).

1. Incoming packets from network 192.168.21.0 are


blocked.
2. Incoming packets destined for internal TELNET
server (port 23) are blocked.
3. Incoming packets destined for host 192.168.21.3 are
blocked.
4. All well-known services to the network 192.168.21.0
are allowed.
Second Generation- Stateful Inspection Firewall :
Stateful firewalls (performs Stateful Packet Inspection)
are able to determine the connection state of packet,
unlike Packet filtering firewall, which makes it more
efficient.
Third Generation- Application Layer Firewall :
Application layer firewall can inspect and filter the
packets on any OSI layer, up to the application layer. It
has the ability to block specific content, also recognize
when certain application and protocols (like HTTP,
FTP) are being misused.

Next Generation Firewalls (NGFW) : Next


Generation Firewalls are being deployed these days to
stop
modern security breaches like advance malware attacks and
application-layer attacks.

 Secure Sockets Layer


Secure Sockets Layer (SSL) is a standard technique for transmitting
documents securely across a network. SSL technology, created by Netscape,
establishes a secure connection between a Web server and a browser,
ensuring private and secure data transmission. SSL communicates using the
Transport Control Protocol (TCP).

The term "socket" in SSL refers to the method of sending data via a network
between a client and a server.

A Web server requires an SSL certificate to establish a secure SSL connection


while using SSL for safe Internet transactions. SSL encrypts network
connection segments atop the transport layer, a network connection
component above the program layer.

SSL is based on an asymmetric cryptographic process in which a Web


browser generates both a public and a private (secret) key. A certificate
signing request is a data file that contains the public key (CSR). Only the
recipient receives the private key.

Benefits of SSL:
o Data integrity: The data can't be tempered as it is not sent as a plain text, so
even if it is intercepted, it could not be decoded.
o Data privacy: The privacy of data is maintained using a series of protocols,
including the SSL Record Protocol, SSL Handshake Protocol, SSL Change CipherSpec
Protocol, and SSL Alert Protocol. So, confidential information, such as social security
number, credit card number, login details, can be transmitted securely.
o Client-server authentication: It uses the standard cryptographic technique to
authenticate the client and server.

 PROXY

Proxy server refers to a server that acts as an intermediary between
the request made by clients, and a particular server for some services
or requests for some resources. There are different types of proxy
servers available that are put into use according to the purpose of a
request made by the clients to the servers. The basic purpose of Proxy
servers is to protect the direct connection of Internet clients and internet
resources. The proxy server also prevents the identification of the
client’s IP address when the client makes any request is made to any
other servers.
OR
The proxy server is a computer on the internet that accepts the
incoming requests from the client and forwards those requests to the
destination server. It works as a gateway between the end-user and the
internet. It has its own IP address. It separates the client system and web
server from the global network.

There are two main purposes of proxy server:

o To keep the system behind it anonymous.

o To speed up access to a resource through caching.

Types of Proxy Servers


1. Open or Forward Proxy Server: It is the most widely recognized
type of intermediary worker that is gotten to by the customer. An
open or forward proxy server refers to those sorts of intermediaries
that get demands from web clients and afterward peruse
destinations to gather the mentioned information. After collecting
the data from the sites, it forwards the data to the internet users
directly. It bypasses the firewall made by authorities. The following
image shows forward proxy configuration.
2. Reverse Proxy Server: It is a proxy server that is installed in
the neighborhood of multiple other internal resources. It
validated and processes a transaction in such a way that
the clients do not communicate directly. The most popular
reverse proxies are Varnish and Squid.
3. Split Proxy Server: It is implemented as two programs installed on
two different computers.
4. Transparent Proxy: It is a proxy server that does not modify the
request or response beyond what is required for proxy
authentication and identification. It works on port 80.
5. High Anonymity Proxy: The proxy server that doesn't contain the
proxy server type and the client IP address in a request header.
Clients using the proxy can't be tracked.
6. SSL/TLS Proxy: Handles secure connections, decrypting and
encrypting traffic for SSL/TLS-protected websites. Enhances
security by inspecting encrypted traffic.
7. Web Proxy Server: The proxy that is targeted to the world wide
web is known as a web proxy server.

Advantages of Proxy Server


There are the following benefits of using the proxy server:

o It improves the security and enhances the privacy of the user.


o It hides the identity (IP address) of the user.
o It controls the traffic and prevents crashes.
o Also, saves bandwidth by caching files and compressing incoming traffic.
o Protect our network from malware.
o Allows access to the restricted content.

SN.NO VPN Proxy

VPN ensures encryption,


Proxy does not ensure or provide
authentication and integrity
any security.
1. protection.
SN.NO VPN Proxy

Protocols used in Proxy are FTP


Protocols used in VPN are
(File transfer protocol), SMTP
PTTP (Point to point tunneling
(Simple mail transfer protocol)
protocol), L2TP (Layer 2
HTTP (Hyper Text Transfer
tunneling protocol) etc.
2. Protocol) etc.

3. VPN works on firewall. Proxy works on browsers.

VPN stands for Virtual Private


It does not simulate a private
Network. It simulate a private
network over public network.
4. network over public network.

Proxy uses the anonymous


VPN does not hide the IP network ID instead of actual IP
address of client. address of client (means it hides
5. the IP address of client).

VPN creates tunnel between But proxy does not create tunnel
6. end users. between end users.

VPN offers high amount of Proxy does not offer any type of
7. security. security.

VPN provides seamless and Proxy connection is highly


8. stable connection unstable.

VPNs encrypt all of a user’s


Proxy servers only hide one
web activity, no matter the
website or app.
9. website or app.

10. VPN encrypts the traffic. Proxy does not encrypt traffic.
Voice over Internet Protocol (VoIP)
Voice over Internet Protocol (VoIP) is a technology that allows
you to make voice calls using a broadband Internet connection
rather than an analogue (traditional) phone line. Some VoIP
services allow you to call multiple people at the same time,
while others may allow you to call anyone. They can have or not
have a phone number, which includes local, long-distance,
mobile, and international numbers. Some VoIP services require
you to use your computer or a special VoIP phone, whereas
others allow you to use a regular phone connected to a VoIP
adapter.
How VoIP/InternetVoice Works –

Voice is converted into a digital signal by VoIP services that travel over
the Internet. If the regular phone number is called, the signal is
converted to a regular telephone signal i.e. an analog signal before it
reaches the destination. VoIP can allow you to make a call directly from
a computer having a special VoIP phone, or a traditional phone
connected to a special adapter. Wireless hot spots in locations such as
airports, hospitals, cafes, etc allow you to connect to the Internet and
can enable you to use VoIP service wirelessly.

Advantages of VoIP –

1. Some VoIP services offer features and services that are not available with
a traditional phone, or are available but only for an additional fee.
2. Paying for both a broadband connection and a traditional telephone line
can be avoided.
3. Smoother connection than an analog signal can be provided.

Disadvantages of VoIP –

1. Some VoIP services don’t work during power outages and the service
provider may not offer backup power.
2. Not all VoIP services connect directly to emergency services through
emergency service numbers.
3. VoIP providers may or may not offer directory assistance.

Comparison of VoIP vs. Traditional Phone Services

Features VoIP Traditional Phone Services

Method of transmission Digital Analog

Yes, high-speed
Internet requirement No, traditional phone line
broadband

Lower cost for long- Higher cost for long-


Cost
distance distance

More features and Limited features and


Features and services
services services

Power outages May not work Usually works

Emergency services
May not connect directly Direct connection
access

May or may not be


Directory assistance Usually available
available

Real Time Streaming Protocol (RTSP)


Computer NetworkFile Systemserver

 What is Real Time Streaming Protocol (RTSP)?


Real Time Streaming Protocol (RTSP) is a network control protocol designed
for use in entertainment and communication systems to control streaming
media servers. The protocol is used to establish and control media sessions
between endpoints, and it can support the transmission of video, audio, and
other types of data.
RTSP is similar to HTTP, but it is specifically designed for the control of
streaming media. It allows a client to issue commands to a server, such as
"play," "pause," and "record," and it can also be used to negotiate the
delivery of streaming media.

RTSP is used in a variety of applications, including internet radio, IPTV, and


video-on-demand. It is supported by many media players and servers, and it
is often used in conjunction with other streaming protocols, such as Real-
time Transport Protocol (RTP) and Real-time Transport Control Protocol
(RTCP), to deliver audio and video content over the internet.

Key Components
The key components of RTSP are −

Clients − Clients are typically media players or other software that sends
RTSP requests to servers in order to establish and control media sessions.
Servers − Servers are typically streaming media servers that receive RTSP
requests from clients and respond with session descriptions and other
information. They also stream the media to the client using the agreed-upon
transport protocol.
RTSP requests and responses − RTSP uses a set of requests and responses to
establish and control media sessions. Examples of RTSP requests include
"SETUP," "PLAY," and "TEARDOWN," and examples of RTSP responses
include "200 OK" and "404 Not Found."
Transport protocols − RTSP uses TCP (Transmission Control Protocol) as its
transport protocol for the exchange of RTSP requests and responses.
However, the actual media content is typically delivered using a separate,
UDP-based (User Datagram Protocol) protocol, such as Real-time Transport
Protocol (RTP).
Session descriptions − Session descriptions are used to communicate
information about the media being streamed, such as the media format, the
transport protocol to be used, and the location of the media. Session
descriptions are exchanged between the client and server during the setup of
a media session.
Media − The media being streamed is typically audio or video content,
although RTSP can also be used to stream other types of data. The media is
delivered to the client using the agreed-upon transport protocol.
What is the Real-time Transport Protocol (RTP)?
Real-time Transport Protocol (RTP) is a network protocol for the delivery of
audio and video over the internet. It is designed to provide end-to-end
network transport functions suitable for applications transmitting real-time
data, such as audio and video.

RTP is used in conjunction with the Real-time Transport Control Protocol


(RTCP), which is used to monitor the quality of the data transmission. RTP
provides the actual delivery of the media, while RTCP is used to provide
feedback on the quality of the transmission and to provide other control
information.

RTP is a packet-based protocol, which means that it breaks the


media stream into packets for transmission over the network. Each
packet is given a sequence number, which allows the receiver to
reassemble the packets in the correct order. RTP also includes a
timestamp, which allows the receiver to synchronize the audio and video
streams.

RTP is widely used in a variety of applications, including voice over IP (VoIP),


video conferencing, and streaming media. It is supported by many media
players and servers

Applications of RTP :
1. RTP mainly helps in media mixing, sequencing and time-stamping.
2. Voice over Internet Protocol (VoIP)
3. Video Teleconferencing over Internet.
4. Internet Audio and video streaming.

JavaScript Cookies
A cookie is an amount of information that persists between a server-side
and a client-side. A web browser stores this information at the time of
browsing.
A cookie contains the information as a string generally in the form of a
name-value pair separated by semi-colons. It maintains the state of a
user and remembers the user's information among all the web pages.

How Cookies Works?


o When a user sends a request to the server, then each of that request is treated as a
new request sent by the different user.
o So, to recognize the old user, we need to add the cookie with the response from the
server.
o browser at the client-side.
o Now, whenever a user sends a request to the server, the cookie is added with that
request automatically. Due to the cookie, the server recognizes the users.

How to create a Cookie in JavaScript?


In JavaScript, we can create, read, update and delete a cookie by
using document.cookie property.

The following syntax is used to create a cookie:

1. document.cookie="name=value";

JavaScript Cookie Example


Example 1
Let's see an example to set and get a cookie.

1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <input type="button" value="setCookie" onclick="setCookie()">
7. <input type="button" value="getCookie" onclick="getCookie()">
8. <script>
9. function setCookie()
10. {
11. document.cookie="username=Duke Martin";
12. }
13. function getCookie()
14. {
15. if(document.cookie.length!=0)
16. {
17. alert(document.cookie);
18. }
19. else
20. {
21. alert("Cookie not available");
22. }
23. }
24. </script>
25.
26. </body>
27. </html>
Example 2
HTML

<!DOCTYPE html>

<html>

<body>
<form name="myform" action="">

Enter name:

<input type="text" name="customer" />

<input type="button" value="Set Cookie"

onclick="WriteCookie();" />

</form>

<script type="text/javascript">

function WriteCookie() {

if (document.myform.customer.value == "") {

alert("Please enter value");

return;

cookievalue = escape(

document.myform.customer.value) + ";";

document.cookie = "name=" + cookievalue;

document.write("Setting Cookies : "

+ "name=" + cookievalue);

}
</script>

</body>

</html

Output:

Adding an expiry date (in UTC): We can add expire date for the cookie to
ensure that after that time the cookie will no longer be in use.
Syntax:
document.cookie = "username=geeksforgeeks;
expires=Sun, 16 JAN 2022 12:00:00 UTC";
Deleting the Cookie: When you want to delete the cookie just simply set the
expires parameter and leave the username blank.
document.cookie = "username=;
expires=Sun, 16 JAN 2022 12:00:00 UTC";

HTML | <frame> Tag


HTML Frames are used to divide the web browser window into multiple
sections where each section can be loaded separately. A frameset tag is the
collection of frames in the browser window.
Creating Frames: Instead of using body tag, use frameset tag in HTML to
use frames in web browser. But this Tag is deprecated in HTML 5. The
frameset tag is used to define how to divide the browser. Each frame is
indicated by frame tag and it basically defines which HTML document shall
open into the frame. To define the horizontal frames use row attribute of
frame tag in HTML document and to define the vertical frames use col
attribute of frame tag in HTML document.
Example:

<!DOCTYPE html>
<html>

<head>

<title>Example of HTML Frames using row attribute</title>

</head>

<frameset rows = "20%, 60%, 20%">

<frame name = "top" src =

"C:/Users/dharam/Desktop/attr1.png" />

<frame name = "main" src =

"C:/Users/dharam/Desktop/gradient3.png" />

<frame name = "bottom" src =

"C:/Users/dharam/Desktop/col_last.png" />

<noframes>

<body>The browser you are working does

not support frames.</body>

</noframes>

</frameset>

</html>

Output: The above example basically used to create three horizontal


frames: top, middle and bottom using row attribute of frameset tag and the
noframe tag is used for those browser who doesn’t support noframe.

Example: This example illustrates the col attribute of frameset tag.

<!DOCTYPE html>

<html>

<head>

<title>Example of HTML Frames Using col Attribute</title>

</head>

<frameset cols = "30%, 40%, 30%">

<frame name = "top" src =


"C:/Users/dharam/Desktop/attr1.png" />

<frame name = "main" src =

"C:/Users/dharam/Desktop/gradient3.png" />

<frame name = "bottom" src =

"C:/Users/dharam/Desktop/col_last.png" />

<noframes>

<body>The browser you are working does

not support frames.</body>

</noframes>

</frameset>

</html>

Output: The above example basically used to create three vertical frames:
left, center and right using col attribute of frameset tag.

Attributes of Frameset tag:


 cols: The cols attribute is used to create vertical frames in web browser.
This attribute is basically used to define the no of columns and its size
inside the frameset tag.
The size or width of the column is set in the frameset in the following
ways:
 Use absolute value in pixel
Example:
<frameset cols = "300, 400, 300">
 Use percentage value
Example:
<frameset cols = "30%, 40%, 30%">
 Use wild card values:
Example:
<frameset cols = "30%, *, 30%">
In the above example * will take the remaining percentage for
creating vertical frame.
 rows: The rows attribute is used to create horizontal frames in web
browser. This attribute is used to define no of rows and its size inside the
frameset tag.
The size of rows or height of each row use the following ways:
 Use absolute value in pixel
Example:
<frameset rows = "300, 400, 300">
 Use percentage value
Example:
<frameset rows = "30%, 40%, 30%">
 Use wild card values
Example:
<frameset rows = "30%, *, 30%">
In the above example * will take the remaining percentage for
creating horizontal frame.
 border: This attribute of frameset tag defines the width of border of each
frames in pixels. Zero value is used for no border.
Example:
<frameset border="4" frameset>
 frameborder: This attribute of frameset tag is used to specify whether the
three-dimensional border should be displayed between the frames or not
for this use two values 0 and 1, where 0 defines for no border and value 1
signifies for yes there will be border.
 framespacing: This attribute of frameset tag is used to specify the
amount of spacing between the frames in a frameset. This can take any
integer value as an parameter which basically denotes the value in pixel.
Example:
 <framespacing="20">
 It means there will be 20 pixel spacing between the frames
Attributes of Frame Tag:
 name: This attribute is used to give names to the frame. It
differentiate one frame from another. It is also used to
indicate which frame a document should loaded into.
Example:
 <frame name = "top" src =
"C:/Users/dharam/Desktop/attr1.png" />
 <frame name = "main" src =
"C:/Users/dharam/Desktop/gradient3.png" />
 <frame name = "bottom" src =
"C:/Users/dharam/Desktop/col_last.png" />
Here we use three frames with names as left center and right.
 src: This attribute in frame tag is basically used to define the
source file that should be loaded into the frame.The value of
src can be any url.
Example:
<frame name = "left" src = "/html/left.htm" />
In the above example name of frame is left and source file
will be loaded from “/html/left.htm” in frame.
 marginwidth: This attribute in frame tag is used to specify
width of the spaces in pixels between the border and
contents of left and right frame.
Example:
 <frame marginwidth="20">
 marginheight: This attribute in frame tag is used to specify
height of the spaces in pixels between the border and
contents of top and bottom frame.
Example:
 <frame marginheight="20">
 scrollbar: To control the appearance of scroll bar in frame
use scrollbar attribute in frame tag. This is basically used to
control the appearance of scrollbar. The value of this attribute
can be yes, no, auto. Where the value no denotes there will
be no appearance of scroll bar.
Example:
 <frame scrollbar="no">
Advantages:
 It allows the user to view multiple documents within a single
Web page.
 It load pages from different servers in a single frameset.
 The older browsers that do not support frames can be
addressed using the tag.
Disadvantages: Due to some of its disadvantage it is rarely used in
web browser.
 Frames can make the production of website complicated.
 A user is unable to bookmark any of the Web pages viewed
within a frame.
 The browser’s back button might not work as the user hopes.
 The use of too many frames can put a high workload on the
server.
 Many old web browser doesn’t support frames.
Note: This tag is not supported in HTML5.

What is Scripting Language | Types, Features


A scripting language is a type of programming language that provides to
write scripts using the syntax of a scripting language.
It is interpreted (or evaluated) by a runtime environment called a script
engine or an interpreter.
A script engine or an interpreter is a computer program that executes the
scripts written in a particular scripting language line by line.
Languages that are executed only by interpreter are called interpreted
languages.
The source code of the program or script does not get compiled before it is
executed. It is read directly, one line at a time, by a program called
interpreter.
For example, a JavaScript interpreter is in-built into every modern web
browser that run JavaScript code. We need only a text editor to write
JavaScript code and a web browser to run it.
Scripting language plays a vital role in the information technology
infrastructure for several years. It has been used for all kind of tasks, web
pages, websites, automation, complex software projects, and in the field of
game development.

What is Script?

A script is a program that consists of a sequence of statements. It is written


by using the syntax or commands of a scripting language or interpreted
language. It is embedded in an HTML web page, interpreted, and executed
by a certain scripting engine.
Script is written for various intentions such as automating the processes on
a local computer or to create a web page on the web.
The programming language in which script is written is called scripting
language or simply script language. Programs in scripting languages are
often written to facilitate the enhanced features of websites.
Generally, scripting languages are not compiled (like C++, Java or other
languages) but are interpreted by an interpreter at runtime.

Popular Examples of Scripting Language

The most popular examples of scripting language are as follows:


 JavaScript
 VBScript
 ASP (Active Server Pages)
 PHP (Hypertext Preprocessor)

Key Features of Scripting Language

There are several important features of scripting languages. They are as


follows:
1. Scripting languages can be directly embedded into an application
or in a variety of environments.
2. They are quite easy to learn and use. For example, JavaScript and
PHP are the easiest scripting languages.
3. They provide all of the basic features common to modern
programming languages, such as powerful variable types, basic
operations (addition, subtraction, etc.), standard control statement,
functions, etc.
4. The scripted code is not usually compiled. It is simply interpreted by
the interpreter at runtime.
5. Scripting languages are free and open source (for example,
JavaScript, Python, etc.) that means a programmer can have full
control to view and edit it.
As scripting languages are open source, anyone from anywhere
around the world can contribute to their development .
7. The syntax of scripting language is familiar and similar to the syntax of
other programming languages such as C, C++, or Java.
8. Scripting languages also provides object-oriented functionality, They
offer several benefits including the following:
 Encapsulation: This feature provides limiting access to code and
data.
 Inheritance: This feature provides to create new objects from the
definition of existing engine objects and/or scripted objects.
 Polymorphism: This feature allows us to override the default
behavior of derived object code, whether the object is derived from
scripted objects or engine objects.
9. Scripting languages require less memory from the system because they
are not compiled, are interpreted.

Types of Scripting Language

Scripting language can be classified into two main categories that are as
follows:
 Client-side script
 Server-side script
On a dynamic website or webpage, both client-side and server-side scripts
are involved. Client-side and server-side are sometimes known as front-end
and back-end.

Advantage of Scripting Languages over Programming


languages
There are several advantages of scripting languages over programming
languages that are as follows:
1. Most scripting languages are free and open source. As a result, anyone
from anywhere around the world can utilize it and contribute to their
development.
2. Most of the scripting languages are dynamically typed that makes it quite
easy to write a program.
3. The coding of scripting language is easy to use and learn. To learn
scripting language, there is not required much knowledge of web
technology or other programming languages.
4. The main benefits of scripting language are that they provide very rapid
code edit/run/debug development cycle because we do not have to wait
for them to be compiled.
5. Scripting languages are highly efficient because they provide the limited
number of data structures and variables to use.
6. Scripting languages do not need to be compiled before they are
executed.
7. They are portable, that means they can run on any operating system.

 What is the difference between a markup language


and a scripting language?
A markup language and a scripting language are two different types of
languages that serve different purposes.

A markup language is used to describe and annotate text to indicate its


structure and formatting. Markup languages are used to create
documents that can be interpreted by different applications, such as web
browsers, which can render the document in a visually appealing way.
Examples of markup languages include HTML, XML, and Markdown.

On the other hand, a scripting language is used to automate and control


the behavior of an application. Scripting languages are used to write
scripts that can be executed by applications or systems to perform tasks
such as data processing, system administration, and automation.
Examples of scripting languages include Python, JavaScript, and Ruby.
Here are some key differences between markup languages and scripting
languages:

1. Purpose: Markup languages are used to describe and structure


content, while scripting languages are used to automate and
control applications.
2. Syntax: Markup languages have a predefined syntax that
describes the structure and formatting of content, while scripting
languages have a more flexible syntax that allows developers to
write custom scripts to automate tasks.
3. Execution: Markup languages are interpreted by applications to
render content in a visually appealing way, while scripting
languages are executed by applications or systems to perform
automated tasks.
4. Flexibility: Markup languages are less flexible than scripting
languages because they have a predefined set of tags and
attributes to describe content. Scripting languages, on the other
hand, are more flexible because they allow developers to write
custom scripts that can be tailored to specific tasks.
In summary, markup languages are used to describe and structure
content, while scripting languages are used to automate and control
applications. While there is some overlap between the two, they serve
different purposes and have different syntaxes and execution models.

Difference between Static and Dynamic Web


Pages
Static Web pages: Static Web pages are very simple. It is written in languages such
as HTML, JavaScript, CSS, etc. For static web pages when a server receives a
request for a web page, then the server sends the response to the client without
doing any additional process. And these web pages are seen through a web browser.
In static web pages, Pages will remain the same until someone changes it manually.

Dynamic Web Pages: Dynamic Web Pages are written in languages such as CGI,
AJAX, ASP, ASP.NET, etc. In dynamic web pages, the Content of pages is
different for different visitors. It takes more time to load than the static web
page. Dynamic web pages are used where the information is changed frequently, for
example, stock prices, weather information, etc.
Difference between Static and Dynamic Web Pages:

SL.N
O Static Web Page Dynamic Web Page

In static web pages, Pages will In dynamic web pages, Content of


1. remain same until someone pages are different for different
changes it manually. visitors.

Static Web Pages are simple in


2. Dynamic web pages are complicated.
terms of complexity.

In static web pages, Information are In dynamic web page, Information are
3.
change rarely. change frequently.

Static Web Page takes less time for Dynamic web page takes more time
4.
loading than dynamic web page. for loading.

In Static Web Pages, database is not In dynamic web pages, database is


5.
used. used.

Static web pages are written in Dynamic web pages are written in
6. languages such as: HTML, languages such as: CGI, AJAX, ASP,
JavaScript, CSS, etc. ASP.NET, etc.

Dynamic web pages contains


Static web pages does not contain
7. application program for different
any application program .
services.

Dynamic web pages require


Static web pages require less work
8. comparatively more work and cost in
and cost in designing them.
designing them.
HTML Lists
HTML Lists are used to specify lists of information. All lists may contain one or more
list elements. There are three different types of HTML lists:

1. Ordered List or Numbered List (ol)


2. Unordered List or Bulleted List (ul)
3. Description List or Definition List (dl)

Note: We can create a list inside another list, which will be termed as nested List.

HTML Ordered List or Numbered List


In the ordered HTML lists, all the list items are marked with numbers by default. It is
known as numbered list also. The ordered list starts with <ol> tag and the list items
start with <li> tag.

1. <ol>
2. <li>Aries</li>
3. <li>Bingo</li>
4. <li>Leo</li>
5. <li>Oracle</li>
6. </ol>

Output:

1. Aries
2. Bingo
3. Leo
4. Oracle

Click here for full details of HTML ordered list. HTML Ordered List

HTML Unordered List or Bulleted List


In HTML Unordered list, all the list items are marked with bullets. It is also known as
bulleted list also. The Unordered list starts with <ul> tag and list items start with the
<li> tag.

1. <ul>
2. <li>Aries</li>
3. <li>Bingo</li>
4. <li>Leo</li>
5. <li>Oracle</li>
6. </ul>

Output:

o Aries
o Bingo
o Leo
o Oracle

Click here for full details of HTML unordered list. HTML Unordered List

HTML Description List or Definition List


HTML Description list is also a list style which is supported by HTML and XHTML. It is
also known as definition list where entries are listed like a dictionary or encyclopedia.

The definition list is very appropriate when you want to present glossary, list of terms
or other name-value list.

The HTML definition list contains following three tags:

1. <dl> tag defines the start of the list.


2. <dt> tag defines a term.
3. <dd> tag defines the term definition (description).

1. <dl>
2. <dt>Aries</dt>
3. <dd>-One of the 12 horoscope sign.</dd>
4. <dt>Bingo</dt>
5. <dd>-One of my evening snacks</dd>
6. <dt>Leo</dt>
7. <dd>-It is also an one of the 12 horoscope sign.</dd>
8. <dt>Oracle</dt>
9. <dd>-It is a multinational technology corporation.</dd>
10. </dl>

Output:

Aries

-One of the 12 horoscope sign.

Bingo

-One of my evening snacks

Leo

-It is also an one of the 12 horoscope sign.

Oracle

-It is a multinational technology corporation.

Difference between an id and class in HTML

In HTML, both Id and Class are the element selector and are used to identify
an element based on the name assign to these parameters. ID and Class
selectors are the most widely used element selectors in CSS (HTML). The
basic difference between ID and Class is that the ID selector is applied only
to one element in a page, whereas the class selector can be applied to
several elements on a single page.

Read this article to find out more about "id" and "class" in HTML and how
they are different from each other.

What is ID in HTML?
In HTML, the "id" selector is used id attribute of an element. For an HTML
element, the "id" name starts with the symbol '#' followed by a unique
name. One important characteristics of the id element is that we can only
attach one id selector to an element. Hence, the ID selector is always unique
within an HTML page.

Example of ID Selector
<!DOCTYPE html>
<html>
<head>
<title>
Id demo
</title>
<style>
#idDemo{
color:green;
font-size:25px;
}
</style>
</head>
<body style="text-align:center">
<h1>Get element by Id</h1>
<p id="idDemo">Demo for Id selector</p>
</body>
</html>

What is CLASS in HTML?


In HTML, the "class" selector is used to select an element with a specific class
attribute. The class selector starts with a period (.) followed by a class name.
Unlike the id selector, we can attach multiple selector to an HTML element.
Therefore, the class can be applied many time within a page. The important
point to note about the class selector is that the class name must not be
started with a number.

Example of Class Selector


<!DOCTYPE html>
<html>
<head>
<title>
Class demo
</title>
<style>
.classDemo{
color:orange;
font-size:25px;
}
</style>
</head>
<body style="text-align:center">
<h1>Get element by class<h1>
<p class="classDemo">Demo for class selector</p>
</body>
</html>

Difference between ID and CLASS in HTML

Id Class

1. In HTML, for an element, the ID name starts with the "class" assigned to an element has its name sta
"#" symbol followed by a unique name assigned to it. followed by class name.

2. Only one ID selector can be attached to an element. Multiple class selectors can be attached to an e

3. ID is unique in a page and can only apply to at most The class can be applied to multiple elements s
one element multiple times on a single page.

The following are the important differences between Id and Class & minius;

Difference between HTTP GET and POST


Methods

HTTP GET: The Hypertext Transfer Protocol(HTTP) Get method is mainly used at
the client (Browser) side to send a request to a specified server to get certain data or
resources. Using this method the server should only let us receive the data and not
change its state. Hence it is only used to view something and not to change it. Get
method is one of the most used HTTP method. The request parameter of the get
method is appended to the URL. Get request is better for the data which does not need
to be secure (It means the data which does not contain images or word documents).
Example: In the following HTML code we have created a form with text field as
Username and City. we have also included a PHP file getmethod.php where our data
would be sent after we click the submit button.
 index.html

<!DOCTYPE html>

<html>

<body>

<form action="getmethod.php" method="GET">

Username: <input type="text"

name="username" /> <br>

City: <input type="text"

name="city" /> <br>

<input type="submit" />

</form>

</body>

</html>
In the following PHP code using the GET method we have displayed the Username
and city.

 getmethod.php

<!DOCTYPE html>

<html>

<body>

Welcome

<?php echo $_GET["username"]; ?> </br>

Your City is:

<?php echo $_GET["city"]; ?>

</body>

</html>

Output: Data passed in GET method is clearly visible in the address bar, which can
compromise the security.

HTTP POST: The Hypertext Transfer Protocol(HTTP) Post method is mainly used at
the client (Browser) side to send data to a Specified server in order to create or rewrite
a particular resource/data. This data sent to the server is stored in the request body of
the HTTP request. Post method eventually leads to the creation of a new resource or
updating an existing one. Due to this dynamic use, it is one of the most used HTTP
methods. It is not one of the most secure methods because the data that is been sent is
included in the body of the request and not in the URL. Post request is better for the
data which needs to be secure (It means the data which contains images or word
documents).
Example: In the following HTML code we have created a form with text field as
Username and Area of study. we have also included a PHP file postmethod.php,
where our data would be sent after we click the submit button.
 index.html

<!DOCTYPE html>

<html>

<body>

<form action="postmethod.php" method="post">

Username: <input type="text"

name="username" /> <br>

Area of Study: <input

type="text" name="area" /> <br>

<input type="submit" />

</form>

</body>

</html>

In the following PHP code using the POST method we have displayed the Username
and Area of study .
 postmethod.php

<!DOCTYPE html>

<html>

<body>

Welcome

<?php echo $_POST["username"]; ?> </br>

YOur Area of Study is:

<?php echo $_POST["area"]; ?>

</body>

</html>

Output: Data passed in POST method is not shown in the address bar, which
maintains the security.

Difference between HTTP GET and HTTP POST

HTTP GET HTTP POST

In GET method we can not send large In POST method large amount of data
amount of data rather limited data is sent can be sent because the request
because the request parameter is appended parameter is appended into the
into the URL. body.
GET request is comparatively better than POST request is comparatively less
Post so it is used more than the better than Get so it is used less than
Post request. the Get request.

POST request is comparatively more


GET request is comparatively less secure
secure because the data is not
because the data is exposed in the URL bar.
exposed in the URL bar.

Request made through GET method are Request made through POST method
stored in Browser history. is not stored in Browser history.

GET method request can be saved as POST method request can not be
bookmark in browser. saved as bookmark in browser.

Request made through POST method


Request made through GET method are
are not stored in cache memory of
stored in cache memory of Browser.
Browser.

Data passed through GET method can be Data passed through POST method
easily stolen by attackers. can not be easily stolen by attackers.

In GET method only ASCII characters are In POST method all types of data is
allowed. allowed.

Difference between Session and Cookies


1. Session :
A session is used to save information on the server momentarily so that it may be
utilized across various pages of the website. It is the overall amount of time spent on
an activity. The user session begins when the user logs in to a specific network
application and ends when the user logs out of the program or shuts down the
machine.
Session values are far more secure since they are saved in binary or encrypted form
and can only be decoded at the server. When the user shuts down the machine or logs
out of the program, the session values are automatically deleted. We must save the
values in the database to keep them forever.
2. Cookie :
A cookie is a small text file that is saved on the user’s computer. The maximum file
size for a cookie is 4KB. It is also known as an HTTP cookie, a web cookie, or an
internet cookie. When a user first visits a website, the site sends data packets to the
user’s computer in the form of a cookie.
The information stored in cookies is not safe since it is kept on the client-side in a text
format that anybody can see. We can activate or disable cookies based on our needs.

Difference Between Session and Cookies

Cookie Session

Cookies are client-side files on a


Sessions are server-side files that contain user
local computer that hold user
data.
information.

Cookies end on the lifetime set by When the user quits the browser or logs out of
the user. the programmed, the session is over.

It can only store a certain amount


It can hold an indefinite quantity of data.
of info.

We can keep as much data as we like within a


The browser’s cookies have a session, however there is a maximum memory
maximum capacity of 4 KB. restriction of 128 MB that a script may consume
at one time.

Because cookies are kept on the


To begin the session, we must use the session
local computer, we don’t need to
start() method.
run a function to start them.
Session are more secured compare than
Cookies are not secured.
cookies.

Cookies stored data in text file. Session save data in encrypted form.

Cookies stored on a limited data. Session stored a unlimited data.

In PHP, to get the data from


In PHP , to get the data from Session,
Cookies , $_COOKIES the global
$_SESSION the global variable is used
variable is used

In PHP, to destroy or remove the data stored


We can set an expiration date to
within a session, we can use the
delete the cookie’s data. It will
session_destroy() function, and to unset a
automatically delete the data at
specific variable, we can use the unset()
that specific time.
function.

HTML vs XML


HTML: HTML (Hyper Text Markup Language) is used to create web pages and
web applications. It is a markup language. By HTML we can create our own static
page. It is used for displaying the data not to transport the data. HTML is the
combination of Hypertext and Markup language. Hypertext defines the link between
the web pages. A markup language is used to define the text document within tag
which defines the structure of web pages. This language is used to annotate (make
notes for the computer) text so that a machine can understand it and manipulate text
accordingly.
Example:
 html

<!DOCTYPE html>
<html>

<head>

<title>GeeksforGeeks</title>

</head>

<body>

<h1>GeeksforGeeks</h1>

<p>A Computer Science portal for geeks</p>

</body>

</html>

Output:

 XML: XML (eXtensible Markup Language) is also used to create web


pages and web applications. It is dynamic because it is used to transport
the data not for displaying the data. The design goals of XML focus on
simplicity, generality, and usability across the Internet. It is a textual data
format with strong support via Unicode for different human languages.
Although the design of XML focuses on documents, the language is
widely used for the representation of arbitrary data structures such as
those used in web services.
Example:
 html

<?xml version = "1.0"?>


<contactinfo>

<address category = "college">

<name>G4G</name>

<College>Geeksforgeeks</College>

<mobile>2345456767</mobile>

</address>

</contactinfo>

Output:
G4G
Geeksforgeeks
2345456767
Difference between HTML and XML: There are many differences
between HTML and XML. These important differences are given below:
HTML XML

1. It was written in 1993. It was released in 1996.

HTML stands for Hyper Text Markup XML stands for Extensible Markup
2.
Language. Language.

3. HTML is static in nature. XML is dynamic in nature.

It was developed by Worldwide Web


4. It was developed by WHATWG.
Consortium.

It is termed as a presentation It is neither termed as a presentation


5.
language. nor a programming language.
XML provides a framework to define
6. HTML is a markup language.
markup languages.

7. HTML can ignore small errors. XML does not allow errors.

8. It has an extension of .html and .htm It has an extension of .xml

9. HTML is not Case sensitive. XML is Case sensitive.

10
HTML tags are predefined tags. XML tags are user-defined tags.
.

11 There are limited number of tags in


XML tags are extensible.
. HTML.

12 HTML does not preserve white


White space can be preserved in XML.
. spaces.

13 HTML tags are used for displaying XML tags are used for describing the
. the data. data not for displaying.

14 In HTML, closing tags are not


In XML, closing tags are necessary.
. necessary.

15
HTML is used to display the data. XML is used to store data.
.

16 HTML does not carry data it just XML carries the data to and from the
. displays it. database.

17 IN XML, the objects are expressed by


HTML offers native object support.
. conventions using attributes.
XML document size is relatively large
18 HTML document size is relatively
as the approach of formatting and the
. small.
codes both are lengthy.

An additional application is not DOM(Document Object Model) is


19
required for parsing of JavaScript required for parsing JavaScript codes
.
code into the HTML document. and mapping of text.

Some of the tools used for HTML


Some of the tools used for XML are:
are:
20  Oxygen XML
 Visual Studio Code
.  XML Notepad
 Atom
 Liquid Studio
 Notepad++

PHP Variable Scope


The scope of a variable is defined as its range in the program under
which it can be accessed. In other words, "The scope of a variable is the
portion of the program within which it is defined and can be accessed."

PHP has three types of variable scopes:

1. Local variable
2. Global variable
3. Static variable

Local variable
The variables that are declared within a function are called local variables
for that function. These local variables have their scope only in that
particular function in which they are declared. This means that these
variables cannot be accessed outside the function, as they have local
scope.
A variable declaration outside the function with the same name is
completely different from the variable declared inside the function. Let's
understand the local variables with the help of an example:

File: local_variable1.php

1. <?php
2. function local_var()
3. {
4. $num = 45; //local variable
5. echo "Local variable declared inside the function is: ". $num;
6. }
7. local_var();
8. ?>

Output:

Local variable declared inside the function is: 45

File: local_variable2.php

1. <?php
2. function mytest()
3. {
4. $lang = "PHP";
5. echo "Web development language: " .$lang;
6. }
7. mytest();
8. //using $lang (local variable) outside the function will generate an error
9. echo $lang;
10. ?>

Output:

Web development language: PHP


Notice: Undefined variable: lang in D:\xampp\htdocs\program\p3.php on line
28

Global variable
The global variables are the variables that are declared outside the
function. These variables can be accessed anywhere in the program. To
access the global variable within a function, use the GLOBAL keyword
before the variable. However, these variables can be directly accessed or
used outside the function without any keyword. Therefore there is no
need to use any keyword to access a global variable outside the function.

Let's understand the global variables with the help of an example:

Example:
File: global_variable1.php

1. <?php
2. $name = "Sanaya Sharma"; //Global Variable
3. function global_var()
4. {
5. global $name;
6. echo "Variable inside the function: ". $name;
7. echo "</br>";
8. }
9. global_var();
10. echo "Variable outside the function: ". $name;
11. ?>

Output:

Variable inside the function: Sanaya Sharma


Variable outside the function: Sanaya Sharma
Note: Without using the global keyword, if you try to access a global variable
inside the function, it will generate an error that the variable is undefined.

Example:
File: global_variable2.php

1. <?php
2. $name = "Sanaya Sharma"; //global variable
3. function global_var()
4. {
5. echo "Variable inside the function: ". $name;
6. echo "</br>";
7. }
8. global_var();
9. ?>

Output:

Notice: Undefined variable: name in D:\xampp\htdocs\program\p3.php on line


6
Variable inside the function:

Using $GLOBALS instead of global


Another way to use the global variable inside the function is predefined $GLOBALS
array.

Example:

File: global_variable3.php

1. <?php
2. $num1 = 5; //global variable
3. $num2 = 13; //global variable
4. function global_var()
5. {
6. $sum = $GLOBALS['num1'] + $GLOBALS['num2'];
7. echo "Sum of global variables is: " .$sum;
8. }
9. global_var();
10. ?>

Output:

Sum of global variables is: 18

If two variables, local and global, have the same name, then the local variable has
higher priority than the global variable inside the function.

Example:

File: global_variable2.php
1. <?php
2. $x = 5;
3. function mytest()
4. {
5. $x = 7;
6. echo "value of x: " .$x;
7. }
8. mytest();
9. ?>

Output:

Value of x: 7
Note: local variable has higher priority than the global variable.

What is an Array?
An array is a special variable, which can hold
more than one value at a time.
An array can hold many values under a single
name, and you can access the values by
referring to an index number.

Create an Array in PHP


In PHP, the array() function is used to create an
array:

array();
In PHP, there are three types of arrays:

Indexed arrays - Arrays with a numeric index


Associative arrays - Arrays with named keys
Multidimensional arrays - Arrays containing one
or more arrays.

<!DOCTYPE html>
<html>
<body>

<?php
$cars = array("Volvo", "BMW", "Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " .
$cars[2] . ".";
?>

</body>
</html>
Get The Length of an Array - The count()
Function
The count() function is used to return the length
(the number of elements) of an array:

<!DOCTYPE html>
<html>
<body>

<?php
$cars = array("Volvo", "BMW", "Toyota");
echo count($cars);
?>
</body>
</html>

Loop Through an Indexed Array


To loop through and print all the values of an
indexed array, you could use a for loop, like this:
<?php
$cars = array("Volvo", "BMW", "Toyota");
$arrlength = count($cars);

for($x = 0; $x < $arrlength; $x++) {


echo $cars[$x];
echo "<br>";
}
?>

</body>
</html>

PHP - Sort Functions For Arrays


In this chapter, we will go through the following PHP array sort
functions:

sort() - sort arrays in ascending order


rsort() - sort arrays in descending order
asort() - sort associative arrays in ascending order, according to the
value

 What is a Cookie?
A cookie is often used to identify a user. A cookie is a
small file that the server embeds on the user's computer.
Each time the same computer requests a page with a
browser, it will send the cookie too. With PHP, you can
both create and retrieve cookie values.
<?php
$cookie_name = "user";
$cookie_value = "John Doe";
setcookie($cookie_name, $cookie_value, time()

 What is an Exception
With PHP 5 came a new object oriented way of dealing with
errors.

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.

Try, throw and catch


To avoid the error from the example above, we need to create the
proper code to handle an exception.

Proper exception code should include:

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"
throw - This is how you trigger an exception. Each "throw" must have
at least one "catch"
catch - A "catch" block retrieves an exception and creates an object
containing the exception information

<?php
//create function with an exception
function checkNum($number) {
if($number>1) {
throw new Exception("Value must be 1 or below");
}
return true;
}
//trigger exception in a "try" block
try {
checkNum(2);
//If the exception is thrown, this text will not be shown
echo 'If you see this, the number is 1 or below';
}
//catch exception
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
}
?>

You might also like