PHP Programming
PHP Programming
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.
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
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.
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.
You must see the status turns green on Apache and MySQL.