Web Programming
Web Programming
Programming
Tutorial class for Computer Science students
Contents
• Client-side refers to the part of an application • Server-side refers to the part of an application that
that runs on the user's device, typically in
a web browser. runs on the server,
• This includes HTML, CSS, and JavaScript, • It typically uses a language like PHP, Python, or
Ruby.....
• It can be more responsive and interactive than
server-side code. • This includes code that interacts with
databases, processes user input, and
generates dynamic content.
In a typical web application, the client-side code sends requests to the server-side code
using HTTP (Hypertext Transfer Protocol). The server-side code processes the request, generates a response,
and sends it back to the client-side code, which then displays the updated content to the user.
TERMINOLOGIES
• Web page: A document which can be displayed in a web browser such as Firefox,
Google Chrome, Opera, Microsoft Internet Explorer or Edge, or Apple's Safari.
These are also often called just "pages."
• Website: is a collection of web pages and related content that is identified by a
common domain name and published on at least one web server.
The first page of a website is called home page.
Static websites: ones that are fixed and display the same content for every user,
usually written exclusively in HTML.
Dynamic websites: one that can display different content and provide user
interaction, by making use of advanced programming and databases in addition
to HTML
TERMINOLOGIES
• search engine - A web service that helps you find other web
pages, such as Google, Bing, Yahoo, or DuckDuckGo.
TERMINOLOGIES
Hypertext - It’s a text which contains links to other texts. Hypertext documents
are interconnected by hyperlinks, which are typically activated by a mouse click,
keypress set, or screen touch.
Hyperlink - It’s a text, images, graphics that, when clicked with a mouse (or activated
by keystrokes) will connect the user to a new Web site. The link is usually obvious,
such as underlined text or a "button" of some type, but not always
Hypertext Transfer Protocol (HTTP) - It is the set of rules by which Web pages are
transferred across the Internet.
TERMINOLOGIES
• Uniform Resource Locator (URL) - URL is one of the key concepts of the Web. It
is the mechanism used by browsers to retrieve any published resource on the
web.
WEB DEVELOPMENT
Web development is coding or programming, which enables
website functionality based on client requirements and deals with
building websites’ non-design aspect.
2 3 5 and 6 are four essential tags that form the basic structure called Document Structure tags.
U N D E R S TA N D I N G C S S
• CSS stands for Cascading Style Sheets, which is a style sheet language
used to describe the look and formatting of a document written in
HTML, XHTML, or XML.
Element Selectors
• These selectors target elements based on their element type. For example, p targets all
paragraph elements, h1 targets all heading 1 elements, and so on.
Class Selectors
• These selectors target elements based on their class attribute. Class selectors begin with a period
(.) followed by the class name. For example, .my-class targets all elements with the class name
"my-class".
ID Selectors
• These selectors target elements based on their ID attribute. ID selectors begin with a hash (#)
followed by the ID name. For example, #my-id targets the element with the ID "my-id".
CSS SELEC TORS
• A combinatory selectors
Child div > p Selects all <p> elements where the parent is a <div> element
Selects the first <p> element that are placed immediately after
Adjacent Sibling div + p
<div> elements
General Sibling p ~ ul Selects every <ul> element that are preceded by a <p> element
U N D E R S TA N D I N G J AVA S C R I P T
• JS is a lightweight programming language (scripting language) , interpreted programming
language that is commonly used for creating interactive web applications.
• JavaScript to program the behavior of web pages
• insert text into HTML document.getElementById("demo").innerHTML = "Hello JavaScript";
• NOT related to Java other than by name and some syntactic similarities
L A N G U A G E F O R M AT O F J S
Comments in JS
// This is a single-line comment in JavaScript
/*
This is a
multi-line
comment in JavaScript
*/
Variable Declaration
// can be reassigned and re-declared later in the program
var message = "Hello, world!";
// can be reassigned but not re-declared and limited to the block scope
let myVariable = "Hello, world!";
const PI = 3.14; // cannot be reassigned and is also limited to the block scope.
JavaScript code can be embedded directly into an HTML file using the <script>, or placed in a separate file
and linked to an HTML file using <script src="filename.js"> tag
D I S P L AY I N G M E S S A G E S
Web Programming 23
ACCESSING ELEMENTS
Web Programming 24
E V E N T S I N J A VA S C R I P T
Python
• Django, Flask, Pyramid
Ruby
• Ruby on Rails, Sinatra, Hanami
Node.js
• Express, Koa, Hapi
P H P F O R S E R V E R - S I D E A P P L I C AT I O N
DEVELOPMENT
• PHP is a popular server-side programming language that is widely
used for web development.
• Some of the key features and advantages of PHP include:
• Open-source and free to use
• Large and active community of developers
• Easy to learn for developers with experience in C or C++
• Built-in support for working with databases and web servers
• Many popular web frameworks and CMSs built with PHP,
including Laravel, Symfony, and WordPress
COMMON USES OF PHP
PHP code can be embedded directly into an HTML code using the php tag <?php …. ?>, and it should be
saved as .php extension
VA R I A B L ES I N P H P
Variable type is determined at runtime based on the value they are assigned.
CONTROL STRUCTURES IN PHP
Control structures are an essential part of programming in PHP and are used extensively in building dynamic
and interactive web applications.
HTML FORM AND PHP
Array Description
Choose a Set
Create a Choose
database 1 2 up database 3
database a database API
system credentials
4
MSQLI PDO
• Only mysql database system • 12 different database systems
• Needs to rewrite the entire code • Needs to change only the
to switch to another database. connection string and a few
• Procedural and Object Oriented queries
• support Prepared Statements • Object Oriented
• support Prepared Statements
MYSQLI VS PDO
TASKS MYSQLI PDO
$s->setFetchMode(PDO::FETCH_ASSOC);
while($row = $result->fetch_assoc())
while($row = $s->fetch())
{
{
echo "id: " . $row["id"]. " -
echo "id:".$row["id"]."-
Fetch result UserName: " . $row["username"]. "-
UserName:".$row["username"]."-
Email:" . $row["email"]. "<br>";
Email:".$row["email"]."<br>";
}
}
Close
Connection $c->close(); $c=null;
SESSION & COOKIES
• In PHP, sessions and cookies are mechanisms used to store data
across multiple requests and responses in web applications.