0% found this document useful (0 votes)
7 views59 pages

Week 1 Slides

The document provides an overview of web applications, distinguishing them from standalone applications, and explains their client-server architecture. It covers the setup of a PHP development environment, including installing XAMPP and creating PHP files, as well as introducing PHP variables, constants, and operators. Additionally, it outlines best practices for comments and variable naming conventions in PHP.

Uploaded by

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

Week 1 Slides

The document provides an overview of web applications, distinguishing them from standalone applications, and explains their client-server architecture. It covers the setup of a PHP development environment, including installing XAMPP and creating PHP files, as well as introducing PHP variables, constants, and operators. Additionally, it outlines best practices for comments and variable naming conventions in PHP.

Uploaded by

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

Introduction to Web

Applications
Standalone Application

 A standalone application runs


independently on a user’s
device.
 It doesn’t require an internet
connection.
 Examples include desktop
software like Microsoft Word
or video games etc.
Web Application
 A web application is accessed via a web browser.
 It relies on internet connectivity.
 Examples include Gmail, Facebook, and online
banking systems.
How Web Applications Work

 Web apps follow a client-server


architecture.
 The client (browser) requests
resources from the server.
 The server processes requests and
sends back responses.
Client Side

 These technologies run in the


user’s browser.

 Responsible for rendering the


user interface.
Server Side

 Server-side technologies handle


business logic and data processing.
 Examples: PHP, Python, Java, Node.js.
 Interact with databases and APIs.
Frontend
Technologies
 Front-end focuses on user experience
(HTML, CSS, JS).
 Includes frameworks like React,
Angular, and Vue.js.
 Responsible for UI design and user
interactions.
 Backend manages server-side
operations.
Backend  Examples: Express.js, Django, Ruby on
Rails, PHP, Python , Java Etc.
Technologies
 Handles data storage, authentication,
and APIs.
Static and Dynamic Web Sites

Static sites have fixed content Dynamic sites generate


(HTML, CSS). content on the fly (using
databases, APIs).
Web apps can
be accessed
Accessibility: from any
device with a
browser.

Features Data is stored


on servers,
Centralized
of Web
making it
data storage: accessible
from

Apps
anywhere.

Web apps can


handle large
Scalability: user bases
and traffic.
Examples of Web Applications

Examples of Web Applications


1. Socialmedia
platforms (e.g., Facebook, Twitter):
1.Connect people globally, share content, and
interact.
2. E-commerce sites (e.g., Amazon, eBay):
1.Facilitate online shopping and transactions.
3. Onlinecollaboration tools (e.g., Google
Docs, Trello):
Introduction to PHP
Setting Up a PHP
Development
Environment
Objective: Learn how to set up a local PHP development
environment.
Installing XAMPP Server

Download Install Start


• Download XAMPP • Install XAMPP • Start XAMPP
• Go to the XAMPP • Run the installer and • Launch XAMPP
website. follow the installation Control Panel.
• Download the wizard. • Start the Apache and
appropriate version • Choose the MySQL services.
for your operating components you want
system (Windows, to install (e.g.,
macOS, or Linux). Apache, MySQL, PHP).
• Set the installation
directory (default is
usually fine).
Testing XAMPP

Verify Open a web


Installation browser.

Type
You should see
http://localhost
the XAMPP
in the address
welcome page.
bar.
Installing Visual Studio Code (VS Code)

Download Install

Download VS Code Install VS Code


• Go to the VS Code website. • Download and install VS Code for your
operating system.
Creating Your First PHP File

Create PHP
Create Folder Open Write Code
File
Create a Folder Open VS Code Create a PHP File Write Some PHP
• Create a folder for your • Open VS Code and • Click File > New File. • <?php
PHP projects (e.g., navigate to your • Save the file with • echo "Hello, PHP!";
“my-php-projects”). project folder. a .php extension (e.g., • ?>
index.php).
Running PHP Code

St • Start XAMPP Services


• Make sure Apache,MYSQL is running in XAMPP.
ar
t
O • Open Browser
• Type http://localhost/my-php-projects/index.php (replace with
p your folder and file names).
• You should see “Hello, PHP!” displayed.
e
n
Introduction to Comments
• Comments are non-executable lines used to annotate code.

• Improve code readability, understanding, and provide


documentation.
Types of PHP Comments

1. Single-line comments: // Comment goes here


2. Multi-line comments: /* Comment block */
Single-line Comments

• Syntax: // followed by the comment text.


• Example: // This is a single-line comment
Multi-line Comments

• Syntax: /* followed by comment text and */ to end.


• Example:
/*
This is a multi-line
comment block
*/
Best Practices

• Use comments to explain complex logic or intentions.


• Keep comments concise and meaningful.
• Regularly review and update comments to ensure
accuracy.
PHP Variables
What are Variables?

 A named container to store data in your PHP program


 The value a variable holds can change throughout the
program execution.
 Think of them as labeled boxes where you can put
different things.
Declaring Variables in PHP

 Variables in PHP start with a dollar sign ($).


 Variable names are case-sensitive.
 Variable names should be descriptive of the data they
hold.
Types of Variables in PHP

 String: For storing text (e.g., $name = "Alice";)


 Integer: For storing whole numbers (e.g., $age =
30;)
 Float: For storing decimal numbers (e.g. $price =
19.99;)
 Boolean: For storing true/false values (e.g.,
$is_active = true;)
Using Variables

 Storing data: Assign values to variables.


 Performing calculations: Use operators (+, -, *, /,
etc.).
 Making decisions: Use variables in conditional
statements (if/else).
 Displaying output: Print or echo variable values.
Rules for naming variables

 Variable names, after the dollar sign, must start with a


letter of the alphabet or the _ (underscore) character.
Rules for naming variables

 Variable names, after the dollar sign, must start with a


letter of the alphabet or the _ (underscore) character.
 Variable names can contain only the characters a–z, A–Z,
0–9, and _ (under‐score).
Rules for naming variables

 Variable names, after the dollar sign, must start with a


letter of the alphabet or the _ (underscore) character.
 Variable names can contain only the characters a–z, A–Z,
0–9, and _ (under‐score).
 Variable names may not contain spaces. If a variable
name must comprise more than one word, a good idea is
to separate the words with the _(underscore) character
(e.g., $user_name).
Rules for naming variables

 Variable names, after the dollar sign, must start with a


letter of the alphabet or the _ (underscore) character.
 Variable names can contain only the characters a–z, A–Z,
0–9, and _ (under‐score).
 Variable names may not contain spaces. If a variable
name must comprise more than one word, a good idea is
to separate the words with the _(underscore) character
(e.g., $user_name).
Rules for naming variables

 Variable names, after the dollar sign, must start with a


letter of the alphabet or the _ (underscore) character.
 Variable names can contain only the characters a–z, A–Z,
0–9, and _ (under‐score).
 Variable names may not contain spaces. If a variable
name must comprise more than one word, a good idea is
to separate the words with the _(underscore) character
(e.g., $user_name).
 Variable names are case-sensitive. The variable
$High_Score is not the same as the variable $high_score.
Introduction to PHP Constant
Variables

- Constant variables in PHP provide a way to define


values that remain unchanged throughout the
execution of a script.

- Unlike regular variables, constant values cannot be


changed once they are defined.
Defining Constants

Syntax: define(name, value)


- Use the `define()` function to define constants.
- Parameters:
- `name`: The name of the constant.
- `value`: The value assigned to the constant.
Accessing Constants

echo SITE_NAME; // Output: My Website


echo MAX_LOGIN_ATTEMPTS; // Output: 3

- Constants can be accessed directly by their name


without using the `$` prefix.
Magic Constants

- PHP provides predefined constants called "magic


constants"
- - Examples:
- `__LINE__`: The current line number in the script.
- `__FILE__`: The full path and filename of the script.
- `__DIR__`: The directory of the script.
Introduction to PHP Operators

 Operators in PHP are symbols that perform operations on variables and


values.
Arithmetic Operators

Assignment Operators

Comparison Operators

Logical Operators
Types of
Operators
Increment/Decrement Operators

Conditional (Ternary) Operator

String Operators
Arithmetic Operators

 Arithmetic operators are used to perform mathematical operations.


 - Addition: +
 - Subtraction: -
 - Multiplication: *
 - Division: /
 - Modulus: %
Assignment Operators

 Assignment operators are used to assign values to variables.


 - Assignment: =
 - Addition assignment: +=
 - Subtraction assignment: -=
 - Multiplication assignment: *=
 - Division assignment: /=
 - Modulus assignment: %=
Comparison Operators

 Comparison operators are used to compare two values.


 - Equal to: ==
 - Not equal to: !=
 - Identical to: ===
 - Not identical to: !==
 - Greater than: >
 - Less than: <
 - Greater than or equal to: >=
 - Less than or equal to: <=
Logical Operators

 Logical operators are used to combine conditional statements.


 - AND: &&
 - OR: ||
 - NOT: !
Increment and Decrement Operators

 Increment and decrement operators are used to increase or decrease


the value of a variable.
 - Increment: ++$x
 - Decrement: --$x
Conditional (Ternary) Operator

 The conditional operator is a shorthand for an if-else statement.


 Syntax: condition ? expression1 : expression2

You might also like