You are on page 1of 19

Introduction to PHP

Session 1

By: Navneet yadav, Mobile: +919728877896

Objectives

Discuss the history of PHP


Identify the need for PHP
List the PHP tools
Write a simple PHP script
Use PHP to generate HTTP headers

By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 2 of 19

History of PHP - I

An advance product of PHP/FI


PHP/FI stands for Personal Home Page/Forms
Interpreter
Rasmus Lerdorf created PHP/FI in the year 1995
PHP/FI got advanced to PHP/FI 2.0 in the year 1997
Andi Gutmans and Zeev Surakshi advanced PHP/FI
2.0 to PHP 3.0 in the year 1997. This was the first
version of recent PHP
By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 3 of 19

History of PHP - II

PHP 3.0 provides a concrete infrastructure for


different databases, protocols, and APIs to the end
users along with the support for object oriented syntax
PHP 3.0 got advanced to PHP 4.0 in the year 1998
PHP 4.0 includes supportive features for more Web
servers, HTTP sessions, output buffering, and security
while handling user inputs
This is the latest version of PHP
By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 4 of 19

Need for PHP

Uses in server-side scripting. It is platform independent


Advantages of using PHP are:
Easy to learn, use, and implement
Free for access
Executes on any platform
Executes scripts from the command line and develops
client-side GUI applications that can operate on any
platform
Uses of PHP are application control, database access, file
access, and graphics
By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 5 of 19

PHP tools and setup - I

Uses for developing and designing a web pages


Contains all the supporting features for the fast developments of
the web sites. These tools are basically the programming text
editors
The tools are:
PHPEd Helps a developer in developing applications by
supporting PHP scripts and its syntaxes. It is freely available
to the users. It is available with version 3.3
PHPDebugger DBG Helps the PHP scripts to get executed
in steps. It helps to trace out the errors in scripts. This tool is
freely available to the users. Its current version is 2.11.23

By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 6 of 19

PHP tools and setup - II

ionCube Standalone PHP Encoder Helps in speeding up


the execution of the scripts. It is freely available. Its
updated version is 3.1. The main functionality of this tool
is that it does not allow the document to get corrupted
Codelock Works with the PHP scripts. It is freely
available with 2.0 versions
PHing Performs various file system operations while
processing a file. The working of this tool depends on the
platform where the PHP is working. It is freely available
for users. Its updated version is 1.0rc2

By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 7 of 19

PHP tools and setup - III

NuSphere PHPEd Uses 3.1.2 version. It is freely


available for the users. It is an Integrated Development
Environment that includes all functionalities for
developing dynamic web sites
xored:WebStudio Uses the updated version of the tool.
Its latest version is 0.2.2. It works with the free availability
for the users. This tool is built on eclipse platform. An
eclipse platform is a tool platform for open source IDE
PHPmole Uses GNOME platform for working with PHP.
Its latest version is 1.3 that is freely available to the users.
This tool is a combination of Dreamweaver software with
Microsoft Visual studio software
By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 8 of 19

PHP tools and setup - IV

Simplewire PHP SMS Software Development kit Works


with the wireless messaging network to send SMS to mobile
phones . It is freely available in 2.3.0 version
Quanta Plus Web Development Environment Uses 2.0
version of tool. It is freely available to the users. It is a web
development tool
K PHP Develop Supports MySQL as a database server. It is
freely available with 0.1.6 version of the software. It has
different modules such as server, server setup, clients and
plugins
Gedit Uses for writing PHP scripts. It gets installed by
default while installing Linux. It is just like a notepad of
windows
By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 9 of 19

Writing a Simple PHP script

Starts with <?php tag and ends with the ?> tag
Scripts are embedded in the BODY tag of the HTML
file
Saves with an extension, .php under the
/var/www/html directory
For example, display a simple text in the browser

By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 10 of 19

Example for Simple PHP Script


Enter the PHP codes in gedit text editor
<HTML>
<BODY>
<?php
echo Hello Everybody;
?>
</BODY>
</HTML>

By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 11 of 19

Output of the PHP Script

Enter http://localhost/stringdisp.php in
the address bar. The output appears, as shown in the
figure

By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 12 of 19

Using PHP to generate HTTP


headers

HTTP is HyperText Transfer Protocol


It is a network transmission protocol
Uses with the help of TCP/IP protocol
Divides into three parts namely, request and response
line, HTTP header, and the body of the protocol

By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 13 of 19

About HTTP header

Sends information to the client or the server about


the application that will be displayed on the
browser
Informs about the application is on request line or
on the response line
Divides into three different categories like general,
entity, and request/response
Generates the HTTP headers using the header()
function
By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 14 of 19

Using header() function

Passes the HTTP commands to the server through


the HTTP protocols using the header()
function
Syntax for using the simple header() function is:
void header (string string)
Where,

string - Includes authenticating or validating strings


for the server. The whole string is enclosed in the single
quotes
By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 15 of 19

Example using header() function

For example, use an authenticating string in the


header() function
<?php
header(WWW-Authenticate:
Negotiate);
?>

By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 16 of 19

Using options of header()


function

The syntax for using header()


http_response_code option is:

function

with

void header (http_response_code)


Where,

http_response_code - Shows the response of the web


server on any request. It shows the response like status or the
location of the client

By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 17 of 19

Example using the option

For example, show the location of the client


<?php
header(Location: http://www.msn.com);
exit;
?>

By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 18 of 19

Summary

PHP is a general purpose scripting language used for


developing dynamic web pages and embedded in HTML tags
PHP is developed from C-modules, therefore the scripts are
also executed from the command line to make client-side GUI
applications
PHP is also used for generating files in various formats like
PDF and HTML formats
PHP script starts with <?php tag and ends up only with the ?>
tag. These scripts are embedded in the HTML tags
PHP uses tools such as text editors for developing and
designing web pages. Gedit is the most popular text editor
used for programming on Linux platform
By: Navneet yadav, Mobile: +919728877896

PHP / Session 1 / Slide 19 of 19

You might also like