Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Lect 01 Introduction to PHP

Chapter 1 introduces PHP, a server-side programming language used for dynamic web development, highlighting its history, features, and common uses. It emphasizes the prerequisites for learning PHP, such as knowledge of HTML, CSS, and JavaScript, and outlines the benefits of using PHP, including its open-source nature and speed. The chapter also covers installation, setup of a development server, and the creation of virtual hosts for web applications.

Uploaded by

mohamedliban972
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lect 01 Introduction to PHP

Chapter 1 introduces PHP, a server-side programming language used for dynamic web development, highlighting its history, features, and common uses. It emphasizes the prerequisites for learning PHP, such as knowledge of HTML, CSS, and JavaScript, and outlines the benefits of using PHP, including its open-source nature and speed. The chapter also covers installation, setup of a development server, and the creation of virtual hosts for web applications.

Uploaded by

mohamedliban972
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Chapter 1:

Introduction
Learning Objectives

01 Introduction

02 Prerequisite PHP language


Chapter 1:
03 Common uses of PHP
Introduction to
PHP 04 How Does PHP Work

05 Why Use PHP?

06 Testing the Installation


Introduction
• PHP is a server-side programming language used to create web pages that run
dynamically on the server before being sent to the client. Established in 1994, PHP
is a robust and easy-to-learn language that has become a well-established tool in
web development. The name "PHP" stands for "PHP: Hypertext Preprocessor,"
which is a recursive acronym.
• PHP is commonly embedded in HTML and serves as a server-side scripting
language for managing dynamic content, handling databases, tracking sessions,
and even building full-fledged e-commerce sites. It is integrated with various
popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and
Microsoft SQL Server, making it highly versatile for different web applications.
• PHP can be used in both object-oriented and procedural programming styles,
offering flexibility for developers. It is an interpreted language, meaning PHP code
is executed on the server rather than being compiled beforehand, which allows for
quicker development cycles and immediate feedback.
Cont.….
• HTTP (Hypertext Transfer Protocol) is the
communication standard that governs the requests
and responses between the client’s browser and
the web server, facilitating the interaction that
enables dynamic web pages powered by PHP.
• A web server is designed to handle multiple
simultaneous requests and constantly listens for
incoming connections. When a request is received
from a client, the server processes the request and
sends back a response to acknowledge its receipt.
This ensures that the client knows the server has
successfully received and is processing the request.
History of PHP
• PHP development began in 1994, when Rasmus Lerdorf wrote several
Common Gateway Interface (CGI) programs in C, which he used to
maintain his personal homepage. He extended them to work with
web forms and to communicate with databases, and called this
implementation "Personal Home Page/Forms Interpreter" or PHP/FI.
• PHP is a general-purpose scripting language geared towards web
development. It was originally created by Danish-Canadian
programmer Rasmus Lerdorf in 1994 and released in 1995.
• The PHP reference implementation is now produced by the PHP
Group. PHP was originally an abbreviation of Personal Home Page,
but it now stands for the recursive initialism PHP: Hypertext
Preprocessor.
Pre- Prerequisite PHP language
To start learning PHP, you should have a basic understanding of the following:
• HTML and CSS: These are the building blocks of web development and are used to
create the structure and layout of a website.
• JavaScript: JavaScript is a client-side scripting language that can be used in
conjunction with PHP to create interactive web pages.
• Understanding of basic programming concepts: This includes understanding
variables, loops, functions, and conditional statements.
• A text editor: You will need a text editor to write and edit your PHP code. Some
popular choices include Visual Studio Code, Sublime Text, Atom, and Notepad++.
• A web server: PHP is a server-side language and needs a web server to run. You can
use a local web server such as XAMPP or WAMP for testing and development.
• Familiarity with databases: PHP can be used to interact with databases such as
MySQL, and it will be helpful to have some understanding of SQL and database
management.
Features of PHP Language
1. Open Source: PHP is free to use and distribute, making it highly accessible for developers.
2. Cross-Platform Compatibility: PHP runs on multiple platforms, including Windows, Linux, and
OS.It can also be integrated with many web servers, such as Apache, Nginx, and IIS.
3. Embedded in HTML: PHP can be embedded directly into HTML, allowing developers to mix PHP
code with static HTML content easily. This makes it a powerful tool for dynamic web
development.
4. Server-Side Scripting: PHP is primarily used for server-side scripting. This means that PHP code is
executed on the server before sending the result to the client, allowing for dynamic content
generation and enhanced user interactivity.
5. Database Integration: PHP supports a wide range of databases, including MySQL, PostgreSQL,
Oracle, and Microsoft SQL Server.
6. Support for Object-Oriented Programming (OOP): PHP supports object-oriented programming,
allowing developers to write more modular, reusable, and maintainable code.
7. Security Features: PHP offers several built-in security features such as data encryption,
authentication methods, and protection against common threats like SQL injection and cross-site
scripting (XSS).
Features of PHP Language
8. Error Reporting: PHP provides robust error handling and debugging capabilities,
making it easier for developers to identify and resolve issues during development.
9. Extensive Documentation and Community Support: PHP has comprehensive
documentation, and its large community provides tutorials, forums, and resources that
help developers troubleshoot and improve their PHP skills.
10. Session Management: PHP allows developers to track and manage user sessions
easily, which is crucial for creating personalized experiences and user authentication in
web applications.
11. Scalability and Performance: PHP can handle a high number of concurrent requests
and scale efficiently, especially when combined with technologies like caching and load
balancing, making it suitable for large-scale web applications.
12. Wide Range of Libraries and Frameworks: PHP has a rich ecosystem of libraries,
frameworks (like Laravel, Symfony, and CodeIgniter), and tools that help streamline
development, increase productivity, and provide ready-made solutions for common
tasks.
What is PHP Language?
• A script is a series of instructions to be executed on other programs or
applications. There are two types of scripting languages – ones
intended for the server-side or the back-end and ones for the client-
side or front-end.
• PHP is a server-side scripting language, which means that a server
executes the instructions in a script. Then, the server provides data on
request, channels the requests, and organizes the information in a
database. When a web server receives a script, it will process the
request and send output to a web browser in an HTML format. A web
server database stores the information so other users can’t access the
data and source code.
• With scripts, users can perform operations like customizing a site,
making dynamic changes to website content, and accessing a
database. Users also often use a scripting language to develop web
applications. As PHP is executed on the server, it is possible to use PHP
with HTML.
Characteristics of PHP language
Five important characteristics make PHP's practical nature possible.
1. Simplicity: PHP is designed to be simple and easy to learn, making it
accessible for beginners and experienced developers alike.
2. Efficiency: PHP is known for its high performance and ability to
handle numerous simultaneous requests with minimal resource
consumption.
3. Security: PHP has a strong focus on security, providing various built-
in tools and best practices for developers to protect their
applications.
4. Flexibility: PHP offers great flexibility in terms of application
development. Developers can use it in procedural or object-oriented
programming (OOP) styles, depending on their preferences and
project requirements.
5. Familiarity: PHP has a syntax that is similar to other popular
programming languages, such as C and JavaScript.
Why Use PHP?
PHP is such a popular language because of its numerous
advantages. Here are some of the benefits of PHP:
• Beginner-friendly. The learning curve is not as steep as other
languages. It is easy for beginners to learn PHP by modifying
parts of HTML.
• Multi-function. Create and customize eCommerce, blogs,
desktop applications, and social media with PHP. Not only that,
you may even send emails using PHP.
• Support. PHP has numerous documentation and information
online as additional support and guidance. There are also plenty
of free online tutorials to learn how to use PHP.
• Speed. PHP is around three times faster than another server-
side language, Python. PHP makes websites load faster, which is
also a great advantage to help improve SEO rankings.
• Low cost. PHP is open-source and free, making it affordable for
everyone to use.
How Does PHP Work
• When a user requests a PHP file, the web server runs the PHP code on the
server and generates an HTML page sent to the user’s web browser. PHP is
a server-side scripting language, meaning it is used to generate dynamic
content that can change depending on the user’s input or other factors.
• Programming language is a formal computer language that combines
Marketing Strategy
instructions to generate a specific output. A programming language has all
the necessary features to develop web applications.
• Scripting language incorporates additional functionalities for a specific
action or function. It interprets scripts embedded into other software
environments at runtime and is more straightforward with its code.
• Web server can usually handle multiple simultaneous requests and spends
its time listening for incoming requests. When one request arrives from a
client, the server sends back a response to confirm its receipt.
• HTTP is a communication standard governing the requests and responses
that take place between the browser running on the client computer and
the web server.
Benefits of PHP

One of the primary benefits of using PHP for web development
is its open-source nature, which means it is free to use and can
be modified to suit the needs of developers.
• PHP has a large and active community of developers who
Marketing Strategy
contribute to the language and support other developers.
• PHP is its cross-platform compatibility. It can run on multiple
platforms, including Windows, Linux, and macOS.
• PHP is easy to learn and has a low barrier to entry, making it an
excellent choice for beginner web developers.
• Hypertext Preprocessor (PHP) is an open-source, free server-
side scripting language widely used in web development.
According to Web Technology Surveys, PHP is used by 78.1% of
all websites, including high-traffic websites like Facebook and
Wikipedia.
Benefits of PHP
• PHP files have a. php file extension. These files can
be
Marketing Strategyused to interact with databases, create and
manipulate files, and perform other tasks required
for web development.
• PHP files can also be included in other files using the
include () and require () functions.
• This allows developers to reuse code and maintain
web applications more efficiently.
Common uses of PHP
• Web Development: PHP is particularly well-suited for building dynamic
websites and web applications. It can be used in conjunction with a variety
of web frameworks and templates, making it easy to create complex,
interactive websites.
Marketing Strategy
• Server-side scripting: PHP can be used to create scripts that run on the
server. These scripts can perform a variety of tasks, such as connecting to a
database, performing calculations, or generating dynamic content.
• Content Management Systems: Many popular Content Management
Systems like WordPress, Joomla and Drupal are built on PHP.
• Web Services: PHP can be used to create web services, which allow different
applications to communicate with each other over the internet.
• Sending emails: PHP has built-in functions that allow for easy sending of
emails from a web application, which can be useful for sending notifications,
confirmations, and other types of automated messages.
• Data Processing: PHP can be used to process large amounts of data and
perform data analysis.
The Request/Response Procedure with HTML Page

Marketing Strategy
Dynamic Web Pages with only PHP

Marketing Strategy
Dynamic Web Pages with PHP & MySQL

Marketing Strategy
Cont.…

• PHP borrows a bit of its syntax from other languages


such as C and Java.
Marketing Strategy
• It is really a hybrid language, taking the best features
from other languages and creating an easy-to-use and
powerful scripting language.
• With PHP, it’s a simple matter to embed dynamic activity
in web pages. When you give pages the .php extension,
they have instant access to the scripting language.
Cont.…
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Marketing Strategy <title>Home Page</title>
</head>
<body>
Hello world!!!
<?php
echo " Today is " . date("l") . ". ";
?>
</body>
</html>
Setting Up a Development Server

• You can use WAMP (stands for Windows Apache MySQL


PHP) or XAMPP (stands for X-OS Apache MySQL PHP Perl)
server. WAMP works only in Windows operating system,
Marketing Strategy
whereas XAMPP is a cross-platform, it works in Windows,
Linux, Mac etc.
• The key difference between them apart from OS support
is security (WAMP was built with security in mind).
• You can download the latest XAMPP server for free from
https://apachefriends.org/download.html. Install and test
it probably.
Testing the Installation
• The first thing to do at this point is verify that everything is working
correctly.
• Start the server and enter either of the following two URLs into the
address bar of your browser: Localhost or 127.0.0.1
Marketing Strategy
• Note that the default port of XAMPP Apache server is 80. Sometimes,
Other application is using that 80 port. So, When you will start XAMPP
server, the XAMPP will through unexpected and notifies the server
port is busy or running another application. e.g.- Skype is using 80
port to run application.
• In this case you much change server port, for example, 8080, then
restart it. You must place a colon followed by that value after either of
the preceding URLs—like this: localhost:8080. You will have to do the
same for all examples:
• localhost:8080/example.php
Create virtual host on XAMPP
• A virtual host is the name given to the localhost for hosting multiple domain
names on a single server. A XAMPP installation can have multiple virtual
hosts.
• A virtual host emulates the functionality of a live server and provides a
similar directory structure and database connectivity.
Marketing Strategy
• Step 1
– Create folder in the dir: C:/xampp/htdocs and name it, for example, BCS-
projects, then create index page in it (index.php).
• Step 2
– Go to dir: C:/xampp/apache/conf/extra/httpd-vhosts.conf
– add the following lines:
– <VirtualHost *:80>
– DocumentRoot "C:/xampp/htdocs/BCS-projects"
– Save the file
– DocumentRoot: The folder where files of a site will exist.
– ServerName: It is the URL for our virtual host.
Index Page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Marketing Strategy
<title>Home Page</title>
</head>
<body>
Hello world!!!
<?php
echo ("Welcome to BSC/BIT virtual host");
?>
</body>
</html>
First Page (cont…)
• Save the file into the root directory (C://xampp/htdocs/project) using the
filename index.php.
• You can now call this page up in your browser by entering the following URLs
Marketing Strategy
in its address bar.
http://project
You do not need to include index.php in the URL.
• The index page is the URL or local file that automatically loads when you
write host name in the URL.
Using a Program Editor
• There are a number of good program editors available such as
Notepad, Editra, Notepad++, Sublime, phpDesigner, Visual
Studio Code, etc. Integrated development environments
Marketing Strategy
(IDEs) offer many additional features such as intellisense, in-
editor debugging, program testing, as well as function
descriptions, autocompletion, highlights the syntax
appropriately using colors to help clarify what’s going on, and
much more.
• We will use Visual Studio Code for this course.
Resource engines or websites
• https://www.w3schools.com/php/php_intro.asp
• https://www.guru99.com/what-is-php-first-php-
Marketing Strategy
program.html
• https://www.hostinger.com/tutorials/what-is-php/
• https://codeinstitute.net/global/blog/what-is-
php-programming/
• www.scriptcase.net
• https://www.tutorialspoint.com/index.htm
THANKS!

You might also like