0% found this document useful (0 votes)
2 views20 pages

PHP Programming

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

PHP Programming

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

PHP PROGRAMMING Interactive Web Applications with PHP and MySQL- Alan

Forbes
UNIT – I Introduction to PHP -Basic Knowledge of websites -
Introduction of Dynamic Website -Introduction to PHP -Scope REFERENCE BOOKS
of PHP -XAMPP and WAMP Installation
1. PHP: The Complete Reference-Steven Holzner.
UNIT – II PHP Programming Basics -Syntax of PHP - 2. DT Editorial Services (Author), ―HTML 5 Black Book
Embedding PHP in HTML Embedding HTML in PHP. (Covers CSS3, JavaScript, XML, XHTML, AJAX, PHP,
Introduction to PHP Variable -Understanding Data Types - jQuery)‖, Paperback 2016, 2ndEdition.
Using Operators Using Conditional Statements -If(), else if()
and else if condition Statement. WEB RESOURCES

UNIT – III Switch() Statements -Using the while() Loop -Using 1. Opensource digital libraries: PHP Programming
the for() Loop PHP 6 Functions. PHP Functions -Creating an
2. [Link]
Array -Modifying Array Elements -Processing Arrays with
Loops - Grouping Form Selections with Arrays -Using Array
UNIT – I
Functions.
INTRODUCTION TO PHP
UNIT – IV PHP Advanced Concepts -Reading and Writing
Basic Knowledge of websites:
Files -Reading Data from a File.
Internet: It is a collection of interconnected networks. A means
of connecting a computer to any other computer anywhere in the
UNIT – V Managing Sessions and Using Session Variables -
world via dedicated routers and servers. When two computers
Destroying a Session Storing Data in Cookies -Setting Cookies.
are connected over the Internet, they can send and receive all
kinds of information such as text, graphics, voice, video, and
TEXT BOOK
computer programs.
1. Head First PHP & MySQL: A Brain-Friendly Guide- 2009-
Lynn mighley and Michael Morrison. World Wide Web (WWW): The World Wide Web (WWW)
is a network of online content that is formatted in HTML and
2. The Joy of PHP: A Beginner's Guide to Programming accessed via HTTP. The term refers to all the interlinked HTML
pages that can be accessed over the Internet. The World Wide underlying source code files.
Web was originally designed in 1991 by Tim Berners-Lee.
Core Technologies: HTML, CSS, and basic JavaScript.
Website: A site or website is a central location of various web
pages that are all related and can be accessed by visiting the Data Storage: Content is hardcoded directly inside the HTML
home page of the website using a browser. files. No database is utilized.

Server Role: The server only acts as a storage facility, instantly


Webpage: A web page is a single document that is displayed passing the request files back to the browser without any
through a web browser. It is a part of a website and can include computation.
text, images, videos, links, and interactive elements. Web pages
are primarily written in HTML (HyperText Markup Language), Examples: Portfolio websites, product landing pages, restaurant
styled with CSS (Cascading Style Sheets), and have dynamic menus, and documentation guides.
elements with JavaScript.
Advantages
Every web page is combination of
Types of web pages Fast Loading: Since there is no database querying or server-
1. Static Web Pages – Does not contain logic side processing, files render instantly.
2. Dynamic Web Pages - Contains logic Low Cost: Highly cost-effective to develop, host, and maintain.
Types of Websites: High Security: Without an active database or server-side
1. Static Website: Fixed content, built with HTML/CSS only. scripts, there are fewer entry points for hackers.
2. Dynamic Website: Content changes based on user input or
server-side logic. Disadvantages

Introduction to static and Dynamic Websites Hard to Update: Every single change requires manual code
editing page-by-page.
Static Websites
No Interactivity: Content cannot adjust to individual user
A static website is like a digital brochure. The data is fixed an preferences or login sessions
remains unchanged unless a developer manually modifies the
Dynamic Websites Data Automation: Feeds, live stock prices, and weather data
A dynamic website functions like an application. The visual update automatically in real time.
structure stays constant, but the information displayed inside
changes dynamically based on parameters like time, location, or Disadvantages
user identity
Slower Initial Load: Pulling information out of databases
Websites that generate content at runtime using server-side and rendering code at runtime takes processing time.
scripting. Higher Development Costs: Building custom databases and
Core Technologies: Server-side scripting (PHP, [Link], backend architectures requires skilled engineers.
Python) and client-side scripts (AJAX, JavaScript).
Introduction to PHP
Data Storage: Content lives separately from layout inside ➢ PHP: Stands for Hypertext Preprocessor.
databases like MySQL or MongoDB. ➢ PHP is a general-purpose scripting language that is
especially suited to server-side web development, in which
Server Role: The server interprets the user's request, executes case PHP generally runs on a web server. Any PHP code in
code, pulls relevant data from a database, builds a custom a requested file is executed by the PHP runtime, usually to
HTML file on the spot, and pushes it to the browser. create dynamic web page content or dynamic images used on
websites or elsewhere.
Examples: E-commerce stores (Amazon), social media ➢ PHP is a widely-used open-source general-purpose scripting
networks (Facebook), and banking apps language that is especially suited for web development and
can be embedded into HTML.
Advantages ➢ PHP is a server-side scripting language designed for web
development but also used as a general-purpose
Highly Interactive: Users can log in, filter items, leave programming language. Originally created by Rasmus
comments, or customize profiles. Lerdorf in 1994,
Easy Content Updates: Non-technical users can add blogs or ➢ PHP started out as a small open source project that evolved
products through a Content Management System (CMS) as more and more people found out how useful it was.
dashboard without touching code. Rasmus Lerdorf unleashed the first version of PHP way back
in 1994.
What does PHP do?
➢ PHP is a recursive acronym for "PHP: Hypertext
Preprocessor". PHP (Hypertext Preprocessor) is a versatile scripting language
➢ PHP is a server side scripting language that is embedded in primarily used for web development, but it can indeed be used
HTML. It is used to manage dynamic content, databases, in multiple ways. Here's a brief overview of the three primary
session tracking, even build entire e commerce sites. ways PHP can be utilized
➢ It is integrated with a number of popular databases, including
MySQL, PostgreSQL, Oracle, Sybase, Informix, and
Microsoft SQL Server. 1. Server-Side Scripting: Server-side scripting is the most
➢ PHP is pleasingly zippy in its execution, especially when common and traditional use of PHP. In this context, PHP is
compiled as an Apache module on the Unix side. The embedded within HTML to create dynamic web pages.
MySQL server, once started, executes even very complex When a user requests a PHP page from a web server, the
queries with huge result sets in record-setting time. server processes the PHP code, which may interact with
➢ PHP supports a large number of major protocols such as databases, files, or other data sources, and generates HTML
POP3, IMAP, and LDAP. PHP4 added support for Java and content to be sent to the user's web browser. This allows for
distributed object architectures (COM and CORBA), making dynamic content generation, user authentication, and other
n-tier development a possibility for the first time. server-side functionalities.
➢ PHP is forgiving: PHP language tries to be as forgiving as 2. Command-Line Scripting: PHP can also be used for
possible. command-line scripting, allowing developers to create
➢ PHP Syntax is C-Like. scripts that run on a server or a local computer without the
need for a web server or browser. These scripts can perform
What is PHP file various tasks, such as data processing, file manipulation, and
➢ PHP files can contain text, HTML, CSS, JavaScript, and system administration. Command-line PHP scripts are
PHP code typically run in a terminal or command prompt and can be
➢ PHP code is executed on the server, and the result is returned scheduled as cron jobs (on Unix-based systems) or as tasks
to the browser as plain HTML in Windows Task Scheduler.
➢ PHP files have extension ".php" 3. Client-Side GUI Applications: While PHP is not
commonly used for creating standalone client-side graphical
user interfaces (GUI), you can use PHP in combination with
other technologies to develop client-side web applications. Common uses of PHP
PHP can generate HTML, CSS, and JavaScript code, which ➢ PHP performs system functions, i.e. from files on a system it
can be rendered in the user's web browser. These can create, open, read, write, and close them.
applications can provide interactive and responsive user ➢ PHP can handle forms, i.e. gather data from files, save data
interfaces. While the bulk of the processing still happens on to a file, through email you can send data, return data to the
the server side, JavaScript plays a more prominent role for user.
client-side interactivity. It's important to note that PHP's ➢ You add, delete, modify elements within your database
primary strength through PHP.
➢ Access cookies variables and set cookies.
➢ Using PHP, you can restrict users to access some pages of
What Can PHP Do? your website.
➢ PHP can generate dynamic page content ➢ It can encrypt data.
➢ PHP can create, open, read, write, delete, and close files on
the server Features:
➢ PHP can collect form data ➢ Server-side scripting language.
➢ PHP can send and receive cookies ➢ Embedded in HTML.
➢ PHP can add, delete, modify data in your database ➢ Open-source and cross-platform.
➢ PHP can be used to control user-access ➢ Supports databases (MySQL, PostgreSQL, MongoDB).
➢ PHP can encrypt data

WHY PHP? Basic Syntax:


➢ PHP runs on various platforms (Windows, Linux, Unix, Mac <?php
OS X, etc.) echo "Hello, World!";
➢ PHP is compatible with almost all servers used today ?>
(Apache, IIS, etc.)
➢ PHP supports a wide range of databases Execution Flow:
➢ PHP is free. Download it from the official PHP resource: ➢ Browser requests a PHP page.
[Link] ➢ Server executes PHP code.
➢ PHP is easy to learn and runs efficiently on the server side ➢ Output (HTML/JSON/XML) sent back to browser.
Example Version Year Important Features
First official version. Added better support for web
PHP 2.0 1995 forms and database communication. Became useful
for building interactive websites.
Completely rewritten. Introduced a parser written
in C, making PHP faster and more efficient.
PHP 3.0 1998 Supported multiple databases and web servers.
Considered the beginning of PHP as a true
programming language.
Major improvement in performance. Introduced
PHP 4.0 2000 support for Object-Oriented Programming (OOP).
➢ If you examine the HTML output of the above example, Widely adopted for developing dynamic websites.
you'll notice that the PHP code is not present in the file sent Introduced Zend Engine 2 for better performance.
from the server to your Web browser. Added exception handling and stronger OOP
PHP 5.0 2004
➢ All of the PHP present in the Web page is processed and support with classes and interfaces. Suitable for
stripped from the page; the only thing returned to the client large-scale applications.
from the Web server is pure HTML output. Added Namespaces to organize large projects.
➢ All PHP code must be included inside one of the three special PHP 5.3 2009 Introduced Late Static Binding. Improved code
markup tags ate are recognised by the PHP Parser management for enterprise applications.
Improved performance. Introduced Short Array
Brief History of PHP PHP 5.4 2012 Syntax ([]) and Traits (reusable code blocks).
Version Year Important Features Simplified coding practices.
Created by Rasmus Lerdorf. Started as Perl scripts Introduced Zend Engine 3, providing significant
to track visits to his online resume. Expanded to performance improvements. Added scalar type
handle forms and databases. Named Personal Home PHP 7.0 2015
PHP/FI 1994 declarations, spaceship operator (<=>), and null
Page/Forms Interpreter (PHP/FI). It was initially a coalescing operator (??).
collection of tools rather than a complete Added Arrow Functions (fn() => expression) and
programming language. PHP 7.4 2019
Typed Properties. Further improved performance
Version Year Important Features Management System
and developer productivity.
3. Database Connectivity
Introduced JIT (Just-In-Time) Compiler for faster
PHP can easily connect with popular databases such as
execution. Added Union Types and Match
PHP 8.0 2020 MySQL, MariaDB, PostgreSQL, and Oracle. It performs
Expressions. Made PHP more modern and
CRUD operations: Create, Read, Update, Delete
developer-friendly.
This makes PHP suitable for database-driven applications.

Scope of PHP 4. E-Commerce Website Development


The scope of PHP refers to the various fields and applications PHP is extensively used in online shopping websites. It helps
where PHP can be used. PHP is a powerful server-side scripting manage products, customer information, shopping carts, and
language that enables developers to create dynamic and payment processing. Examples: Amazon, Flipkart, and other
interactive websites and web applications. Due to its simplicity, online stores.
flexibility, and strong database support, PHP has become one of
the most widely used programming languages for web 5. Content Management Systems (CMS)
development. Many Content Management Systems are built using PHP. These
systems allow users to create and manage website content
Areas of Scope in PHP without extensive programming knowledge.
1. Dynamic Website Development Examples: WordPress, Drupal, Joomla
PHP is widely used to develop dynamic websites. Unlike static
websites, dynamic websites can change their content based on 6. Session and Cookie Management
user actions, database information, or system conditions. PHP can manage user sessions and cookies. This helps websites
Examples: Facebook, Wikipedia, and WordPress websites. remember user information and maintain login sessions.
Applications: User Authentication, Shopping Cart
2. Web Application Development Management and User Preferences
PHP supports the development of complete web applications.
These applications can perform complex tasks and provide 7. File Handling
services through a web browser. PHP provides functions for handling files stored on the server.
Examples: Online Banking System, Hospital Management It can: Create files, Read files, Write files, Delete files
System, Attendance Management System, Library
8. API Development Advantages of PHP Disadvantages of PHP
PHP is used to develop REST APIs and web services. APIs
Large developer community and Older PHP code may not be
allow communication between different software applications. extensive documentation. compatible with newer versions.
9. Command-Line Scripting Provides security features like
PHP scripts can be executed directly from the command prompt Requires careful configuration to
encryption, password protection,
without using a web browser. This feature is useful for ensure security.
and session management.
automation and system administration tasks. PHP has a broad
scope in website development, web applications, e-commerce
Flexible and suitable for small as Not commonly used for mobile or
systems, content management systems, file handling, and API
well as large web applications. desktop application development.
development. Its flexibility and ease of use make it one of the
most popular technologies in web development. Supports Object-Oriented Complex applications often require
Advantages of PHP Disadvantages of PHP Programming (OOP). frameworks for better management.
PHP is open source and free to Poor coding practices can lead to PHP is a powerful, flexible, and widely used server-side
use. security vulnerabilities. scripting language. Although it has some limitations, its
Easy to learn due to its simple Less suitable for desktop application advantages such as ease of learning, database support, and cross-
syntax. development. platform compatibility make it one of the most popular
technologies for web development.
Platform independent and runs Large projects can be difficult to
on Windows, Linux, macOS, and maintain without proper coding
Client–Server Architecture in PHP
Unix. standards.
Client Server Architecture is a computing model in which a
Performance may be lower than client sends a request to a server, and the server processes the
Fast execution and efficient
compiled languages for very large request and sends the appropriate response back to the client.
performance on web servers.
applications. PHP works on the server side and generates dynamic web pages
Supports multiple databases such for users.
Some functions have inconsistent Components of Client–Server Architecture
as MySQL, PostgreSQL, Oracle,
naming conventions.
and MariaDB. Component Description
Can be easily embedded within Debugging large applications can be The user's web browser such as Chrome,
Client
HTML. challenging. Firefox, or Edge.
Component Description
Receives requests from the client and processes
Web Server
them. Example: Apache Server.
PHP Engine Executes PHP scripts on the server.
Stores and retrieves data required by the
Database
application. Example: MySQL.

Working of Client–Server Architecture


Step 1: The user enters a URL in the web browser.
Step 2: The browser sends an HTTP request to the web server.
Step 3: The web server receives the request and passes it to the
PHP engine.
Advantages of Client Server Architecture
Step 4: The PHP engine executes the PHP script.
➢ Centralized data management.
Step 5: If required, PHP communicates with the database to
retrieve or store data. ➢ Better security and access control.
Step 6: The database sends the requested data back to the ➢ Easy maintenance and updates.
PHP engine.
➢ Supports multiple users simultaneously.
Step 7: PHP generates an HTML page using the processed
data. ➢ Efficient resource sharing.

Step 8: The web server sends the generated HTML response Client Server Architecture is the foundation of PHP web
to the browser. applications. In this architecture, the client sends requests
through a web browser, the server processes the requests
Step 9: The browser displays the webpage to the user. using PHP and databases, and the generated response is
returned to the client. This enables the creation of dynamic
Architecture Diagram and interactive websites.
PHP - Environment Setup
XAMPP and WAMP Installation
➢ We have set up the PHP Programming environment on-line,
so that you can compile and execute all the available WAMP
examples on line. It stands for W-Windows, A- Apache, M-MySQL, P-PHP. It is
➢ It gives you confidence in what you are reading and enables a Web development platform that insists the users manage web
you to verify the programs with different options. Feel free apps using PHP, MySQL, and Apache. It uses virtual hosters and
to modify any example and execute it on line. provides top-services.

➢ In order to develop and run PHP Web pages three vital XAMPP
components need to be installed on your computer system. It stands for X-cross platform(Windows, Linux,Mac Os), A-
• WEB SERVER Apache, M-Maria DB or MySQL , P- PHP, P-Perl is an open-
• DATABASE source platform for free.
• PHP PARSER This platform supports both Windows and LINUX.
How to install WAMP?
➢ Web Server − PHP will work with virtually all Web Server Follow the below steps and install WAMP effortlessly.
software, including Microsoft's Internet Information Server
(IIS) but then most often used is freely available Apache Step 1
Server. − [Link] On your web server, go to the official website to download
➢ Download Apache for free here. WAMP [Link]
This will redirect you to the WAMP download page
➢ Database − PHP will work with virtually all database The webserver has two versions. 32-bit and 64-bit. Download
software, including Oracle and Sybase but most commonly the version according to your system configurations.
used is freely available MySQL database. Download Press enter or click to view image in full size
MySQL for free here −[Link]
➢ PHP Parser − In order to process PHP script instructions a
parser must be installed to generate HTML output that can
be sent to the Web Browser. This tutorial will guide you how
to install PHP parser on your computer.
Step 3
Now the “Select Setup Language box” will appear. Here you
have to choose your preferred language. Most of them will
choose English only. And then click “OK”

Step 2 Step 4
Once you click the download option, you will see a pop-up The License Agreement Window will open. Enable the “I accept
message. It will show some warnings. Don’t worry about that. the agreement” and click “Next”
Just leave it and click the link “download directly”
Press enter or click to view image in full size
Step 6
Step 5 The “Select Destination Location” window will open. Here
Now it will provide information on the basic components that select the location to install WAMP on your computer. And click
need to be in your computer, for the proper functioning of “Next”
WAMP Server. Read the information and then click “Next”
Step 7
Now you have to select “Where should Setup place the Step 8
program’s shortcuts?” Browse and select the location. Then Finally the Ready to Install window will open. “Click Install”
click “Next”
Step 10
Step 9 Once the installation is complete, you are shown with the
Yes, the WAMP server starts installing. The WAMP server is information screen. On that screen click “Next”
extracting the files to the selected location. Wait until the
installation completes.
Step 11 That’s all. Your WAMP installation is completed.
Click “Finish” to complete the installation process.

How to install XAMPP?


Here are the step by step instructions to install XAMPP. Move
through the steps carefully to complete the installation.
Get Fenzik Joseph’s stories in your inbox
Join Medium for free to get updates from this writer.
Subscribe
Remember me for faster sign in
Step 1
Download the XAMPP file from the official
website [Link]
Press enter or click to view image in full size

Step 2
On your default Downloads folder you can see the XAMPP file.
Double Click on the XAMPP folder.
The “User Account Control Window” will open. Click “Yes” on
the User Account Control Window. Now you find the warning
”If you have User Account Control on your computer”. Click
“OK” on the warning
Step 4
Now the “setup xampp wizard page” page will be displayed. On
this page you have to select the components which you want to
install. And leave the others as unselected.
You can find some components in grey colour. These are the
components that are mandatory to run the software. And it will
install automatically. Then Click the icon “Next”.

Step 3
The “Setup XAMPP Wizard page” will open. To proceed the
installation, Click “Next” icon
Step 5 If you activate UAC in your computer, then don’t install your
Now the installation folder page will display. Here you have to XAMPP on the hard drive like Local Disk C
choose the destination, where your file needs to be installed. Click the folder shaped icon and select the “Make new folder”
icon at the left bottom of the page and select the folder where
the XAMPP to be installed and click “Ok” to confirm the
destination location.
After selecting the destination folder click “Next”
Step 6
Now you find the page displaying “Bitnami for XAMPP”.
If you want to learn about Bitnami then you can select the
checkbox “ Learn more about Bitnami”.
Otherwise unselect the checkbox. Bitnami is used to install the
open source applications like WordPress, Joomla, Drupal and
many more on the installed XAMPP. Then click the “Next” icon.

Step 8
Now the XAMPP starts installing. Wait for some more time,
until the installation is complete.
Step 7
The “Ready to install” window will open. Click “Next
Steps 9
Step 10
After installation completes, you will find “Completing the
Now XAMPP is asking for your preferred language English or
XAMPP setup Wizard”. On that wizard, Select the check box
German. Select the language and then click “Save”. Mostly we
”Do you want to start the Control Panel now”?. Then Click
select the English language.
“Finish”
If all the above steps went correct, then the XAMPP control
panel will open smoothly.
Step 11
Click the Start button on Apache and [Link] you start
the modules, you can see the PID(Process ID) number and the
port number that every module is using.

And that’s it. You have successfully installed XAMPP.

You must see the status turns green on Apache and MySQL.

You might also like