SlideShare a Scribd company logo
PHP (Hypertext Preprocessor)
-Gursharandeep kaur bajwa
(CTIEMT)
100220314317
IntroductionIntroduction

PHP is stands for ’Hypertext Preprocessor ’ used for making
dynamic web pages and interactive web pages.

PHP is server side scripting language intented to help web
developers build dynamic web pages.

PHP scripts are executed on the server.

PHP supports many databases (MySql ,Oracle,PostgreSQL,Generic
ODBC etc).

PHP was created by Rasmus Lerdrof in 1995.

PHP originally stood for ”PERSONAL HOME PAGE”

PHP is an Open Source software.

PHP is free to download and use.
PHP FilesPHP Files

PHP files can contain text, HTML Tags and scripts.

PHP files are returned to the browser as plain HTML

PHP files have a file extension of ”.php”.
EXECUTION OF PHP PAGE
“PHP is an HTML-embedded scripting language. Much of its syntax is
borrowed from C,Java & Perl with a couple of unique PHP-specific
features thrown in .The goal of the language is to allow web developers
to write dynamically generated pages quickly. ”
Brief History of PHPBrief History of PHP
PHP (PHP: Hypertext Preprocessor) was created by Rasmus Lerdorf
in 1994. It was initially developed for HTTP usage logging and server-
side form generation in Unix

PHP 2 (1995) transformed the language into a Server-side embedded
scripting language. Added database support, file uploads, variables,
arrays, recursive functions, conditionals, iteration, regular
expressions, etc.

PHP 3 (1998) added support for ODBC data sources, multiple
platform support, email protocols (SNMP,IMAP), and new parser
written by Zeev Suraski and Andi Gutmans .

PHP 4 (2000) became an independent component of the web server
for added efficiency. The parser was renamed the Zend Engine. Many
security features were added.

PHP 5 (2004) adds Zend Engine II with object oriented programming,
robust XML support using the libxml2 library, SOAP extension for
interoperability with Web Services, SQLite has been bundled with
PHP
PHP FeaturesPHP Features

Open source / Free software.

Cross Platform to develop, to deploy, and to use.

Power,Robust, Scalable.

Web development specific.

Can be Object Oriented.

It is faster to code and faster to execute.

Large, active developer community.

20 million websites

Support for PHP is free.

Great documentation in many language www.php.net/docs.php
Why use PHP ?Why use PHP ?
1. Easy to use
Code is embedded into HTML. The PHP code is enclosed in special
start and end tags that allow you to jump into and out.
<html>
<head>
<title>Example</title>
</head>
<body>
<?php
echo “Hi , I’m a PHP script! ”;
?>
</body>
</html>
2.Cross Platform
Run on almost any web server on several Operating Systems.
One of the strongest features is the wide range of supported databases.
• Web Server : Apache, Microsoft IIS , Netscape Enterprise Server.
• Operating Systems : Unix (Solaris,Linux),Mac OS, Window
NT/98/2000/XP/2003.
• Supported Databases : dBase,Empress,FilePro (read only),
Hyperware, IBM DB2,InformixIngress,Frontbase,MySql,ODBC,Oracle
etc.
3. Cost Benefits
PHP is free. Open Source code means that the entire PHP community
will contribute towards bug fixes. There are several add-on technologies
(libraries) for PHP that are also free.
DatatypesDatatypes

PHP stores whole numbers in a platform-dependent range.

This range is typically that of 32-bit signed integers. Unsigned
integers are converted to signed values in certain situations.

Arrays can contain elements of any type that handle in PHP .

Including resources, objects, and even other arrays.

PHP also supports strings, which can be used with single quotes,
double quotes, or heredoc syntax.
What does PHP code look like?What does PHP code look like?

Structurally similar to C/C++

Supports procedural and object-oriented paradigm (to some degree)

All PHP statements end with a semi-colon

Each PHP script must be enclosed in the reserved PHP tag
<?php
…
?>
Comments in PHPComments in PHP

Standard C, C++, and shell comment symbols
// C++ and Java-style comment
# Shell-style comments
/* C-style comments
These can span multiple lines
*/
Variables in PHPVariables in PHP

PHP variables must begin with a “$” sign

Case-sensitive ($Foo != $foo != $fOo)

Global and locally-scoped variables
-- Global variables can be used anywhere
-- Local variables restricted to a function or class

Certain variable names reserved by PHP
-- Form variables ($_POST, $_GET)
-- Server variables ($_SERVER)
-- Etc.
Variable usageVariable usage
<?php
$foo = 25; // Numerical variable
$bar = “Hello”; // String variable
$foo = ($foo * 7); // Multiplies foo by
7
$bar = ($bar * 7); // Invalid
expression
?>
EchoEcho

The PHP command ‘echo’ is used to output the parameters passed
to it
--The typical usage for this is to send data to the client’s web-browser

Syntax
-- void echo (string arg1 [, string argn...])
-- In practice, arguments are not passed in parentheses since echo
is a language construct rather than an actual function
Echo exampleEcho example

PHP scripts are stored as human-readable source code and are compiled
on-the-fly to an internal format that can be executed by the PHP engine.

Code optimizers aim to reduce the runtime of the compiled code by reducing
its size and making other changes that can reduce the execution time with the
goal of improving performance.
<?php
$foo = 25; // Numerical
variable
$bar = “Hello”; // String variable
echo $bar; // Outputs Hello
echo $foo,$bar; // Outputs 25Hello
echo “5x5=”,$foo; // Outputs
5x5=25
echo “5x5=$foo”; // Outputs 5x5=25
echo ‘5x5=$foo’; // Outputs 5x5=$foo
?>
Arithmetic OperationsArithmetic Operations

$a - $b // subtraction

$a * $b // multiplication

$a / $b // division

$a += 5 // $a = $a+5 Also works for *= and /=
<?php
$a=15;
$b=30;
$total=$a+$b;
Print $total;
Print “<p><h1>$total</h1>”;
// total is 45
?>
ConcatenationConcatenation
<?php
$string1=“Hello”;
$string2=“PHP”;
$string3=$string1 . “ ” . $string2;
Print $string3;
?>
Hello PHP
Escaping the CharacterEscaping the Character

If the string has a set of double quotation marks that must remain
visible, use the  [backslash] before the quotation marks to ignore and
display them.
<?php
$heading=“”Computer Science””;
Print $heading;
?>
“Computer Science”
PHP Control StructuresPHP Control Structures

Control Structures: Are the structures within a language that allow us
to control the flow of execution through a program or script.

Grouped into conditional (branching) structures (e.g. if/else) and
repetition structures (e.g. while loops).

Example if/else if/else statement:
if ($foo == 0) {
echo ‘The variable foo is equal to 0’;
}
else if (($foo > 0) && ($foo <= 5)) {
echo ‘The variable foo is between 1 and 5’;
}
else {
echo ‘The variable foo is equal to ‘.$foo;
}
If ... Else...If ... Else...
If (condition)
{
Statements;
}
Else
{
Statement;
}
<?php
If($user==“John”)
{
Print “Hello John.”;
}
Else
{
Print “You are not John.”;
}
?>
No THEN in PHP
While LoopsWhile Loops
While (condition)
{
Statements;
}
<?php
$count=0;
While($count<3)
{
Print “hello PHP. ”;
$count += 1;
// $count = $count + 1;
// or
// $count++;
?>
hello PHP. hello PHP. hello PHP.
Date DisplayDate Display
$datedisplay=date(“yyyy/m/d”);
Print $datedisplay;
# If the date is April 1st
, 2009
# It would display as 2009/4/1
$datedisplay=date(“l, F m, Y”);
Print $datedisplay;
# If the date is April 1st
, 2009
# Wednesday, April 1, 2009
2009/4/1
Wednesday, April 1, 2009
Month, Day & Date Format SymbolsMonth, Day & Date Format Symbols
M Jan
F January
m 01
n 1
Day of Month d 01
Day of Month J 1
Day of Week l Monday
Day of Week D Mon
FunctionsFunctions

Functions MUST be defined before then can be called

Function headers are of the format
-- Note that no return type is specified

Unlike variables, function names are not case sensitive (foo(…) ==
Foo(…) == FoO(…))
function functionName($arg_1, $arg_2, …, $arg_n)
Functions exampleFunctions example
<?php
// This is a function
function foo($arg_1, $arg_2)
{
$arg_2 = $arg_1 * $arg_2;
return $arg_2;
}
$result_1 = foo(12, 3); //
Store the function
echo $result_1; // Outputs 36
echo foo(12, 3); // Outputs 36
?>
Include FilesInclude Files
Include “opendb.php”;
Include “closedb.php”;
This inserts files; the code in files will be inserted into current code.
Thiswill provide useful and protective means once you connect to a
database, as well as for other repeated functions.
Include (“footer.php”);
The file footer.php might look like:
<hr SIZE=11 NOSHADE WIDTH=“100%”>
<i>Copyright © 2008-2010 KSU </i></font><br>
<i>ALL RIGHTS RESERVED</i></font><br>
<i>URL: http://www.kent.edu</i></font><br>
PHP FormsPHP Forms

Access to the HTTP POST and GET data is simple in PHPAccess to the HTTP POST and GET data is simple in PHP

The global variables $_POST[] and $_GET[] contain the request dataThe global variables $_POST[] and $_GET[] contain the request data
<?php
if ($_POST["submit"])
echo "<h2>You clicked Submit!</h2>";
else if ($_POST["cancel"])
echo "<h2>You clicked Cancel!</h2>";
?>
<form action="form.php" method="post">
<input type="submit" name="submit" value="Submit">
<input type="submit" name="cancel" value="Cancel">
</form>
What is a cookie ?What is a cookie ?
A cookie is a small file that the server embeds on the user's
computer. Each time the same computer requests for a page
with a browser, it will send the cookie too. With PHP, you can
both create and retrieve cookie values.
How To Create a Cookie?How To Create a Cookie?

The setcookie() function is used to create cookies.
Note: The setcookie() function must appear BEFORE the
<html> tag.
setcookie(name, [value], [expire], [path], [domain], [secure]);
This sets a cookie named "uname" - that expires after ten hours.
<?php setcookie("uname", $name, time()+36000); ?>
<html> <body> …
How To Retrieve a Cookie Value?How To Retrieve a Cookie Value?

To access a cookie you just refer to the cookie name as a
variable or use $_COOKIE array

Tip: Use the isset() function to find out if a cookie has been
set.
<html> <body>
<?php
if (isset($uname))
echo "Welcome " . $uname . "!<br />";
else
echo "You are not logged in!<br />"; ?>
</body> </html>
How To Delete a Cookie ?How To Delete a Cookie ?

Cookies must be deleted with the same parameters as they
were set with. If the value argument is an empty string (""),
and all other arguments match a previous call to setcookie,
then the cookie with the specified name will be deleted from
the remote client.
What is a Session?

The session support allows you to register arbitrary numbers
of variables to be preserved across requests.

A visitor accessing your web site is assigned an unique id,
the so-called session id. This is either stored in a cookie on
the user side or is propagated in the URL.

Tip: Use the isset() function to find out if a cookie has been
set.
How to Create a Session ?

The session_start() function is used to create cookies.
<?php
session_start();
?>
How to Retrieve a Session Value ?

Register Session variable
-- session_register('var1','var2',...); // will also create a session
-- PS:Session variable will be created on using even if you will not
register it!

Use it
<?php
session_start();
if (!isset($_SESSION['count']))
$_SESSION['count'] = 0;
else
$_SESSION['count']++;
?>
Storing Session Data

The $_SESSION superglobal array can be
used to store any session data.
e.g.
$_SESSION[‘name’] = $name;
$_SESSION[‘age’] = $age;
Reading Session Data
Data is simply read back from the $_SESSION
superglobal array.
e.g.
$_SESSION[‘name’] = $name;
$_SESSION[‘age’] = $age;
How to Delete a Session Value ?

session_unregister(´varname´);
How to destroy a session:

session_destroy()
PHP DATABASE INTERACTION IN FIVE STEPS
1) Create the Connection
2) Select the Database
3) Perform Database Query
4) Use Returned Data (if any)
5) Close Connection
1. Connect with MySQL RDBMS
mysql_connect($hostName, $userName, $password) or
die("Unable to connect to host $hostName");
2. Connect with database
mysql_select_db($dbName) or die("Unable to select
database $dbName");
3. Perform Database Query
Queries: Nearly all table interaction and management is done through
queries:
Basic information searches
$query = "SELECT FirstName, LastName, DOB, Gender FROM
Patients WHERE Gender = '$Gender‘ ORDER BY FirstName
DESC";
$Patients = mysql_query($SQL);
Editing, adding, and deleting records and tables
$query = "INSERT INTO Patients (FirstName, LastName)
VALUES('$firstName', '$lastName')";
$Patients = mysql_query($SQL);
4. Process Results (if any)
• Many functions exist to work with database results
mysql_num_rows()
– Number of rows in the result set
– Useful for iterating over result set
mysql_fetch_array()
– Returns a result row as an array
– Can be associative or numeric or both (default)
– $row = mysql_fetch_array($query);
– $row[‘column name’] :: value comes from database row with specified
column name
Process Results Loop
• Easy loop for processing results:
$result = mysql_query($query;
$num_rows = mysql_num_rows($query);
for ($i=0; $i<$num_rows; $i++) {
$row = mysql_fetch_array($result);
// take action on database results here
}
5. Closing Database Connection
• mysql_close()
– Closes database connection
– Only works for connections opened with mysql_connect()
– Connections opened with mysql_pconnect() ignore this call
– Often not necessary to call this, as connections created by
mysql_connect are closed at the end of the script anyway
THAN ”Q”

More Related Content

What's hot

PHP
PHPPHP
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
Geshan Manandhar
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
Shweta A
 
Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
dharmendra kumar dhakar
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
Elmer Concepcion Jr.
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Collaboration Technologies
 
Php mysql
Php mysqlPhp mysql
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
Mohammed Mushtaq Ahmed
 
PHP
PHPPHP
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
JIGAR MAKHIJA
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Meetendra Singh
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Taha Malampatti
 
Unit 1 php_basics
Unit 1 php_basicsUnit 1 php_basics
Unit 1 php_basicsKumar
 
Php notes
Php notesPhp notes
Php notes
Muthuganesh S
 
Php intro
Php introPhp intro
Php intro
sana mateen
 
Php
PhpPhp
What Is Php
What Is PhpWhat Is Php
What Is Php
AVC
 

What's hot (20)

PHP
PHPPHP
PHP
 
Php introduction
Php introductionPhp introduction
Php introduction
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
 
Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
 
PHP
PHPPHP
PHP
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP slides
PHP slidesPHP slides
PHP slides
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Unit 1 php_basics
Unit 1 php_basicsUnit 1 php_basics
Unit 1 php_basics
 
Php Ppt
Php PptPhp Ppt
Php Ppt
 
Php notes
Php notesPhp notes
Php notes
 
Php intro
Php introPhp intro
Php intro
 
Php
PhpPhp
Php
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 

Similar to Php Tutorial

PHP
PHPPHP
Prersentation
PrersentationPrersentation
Prersentation
Ashwin Deora
 
Basics PHP
Basics PHPBasics PHP
Php mysql training-in-mumbai
Php mysql training-in-mumbaiPhp mysql training-in-mumbai
Php mysql training-in-mumbai
Unmesh Baile
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
Aminiel Michael
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
HambardeAtharva
 
Php mysql
Php mysqlPhp mysql
Php mysql
Ajit Yadav
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
rICh morrow
 
PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessor
adeel990
 
Php
PhpPhp
Php
PhpPhp
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
Guni Sonow
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
anshkhurana01
 
Php
PhpPhp
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Muhamad Al Imran
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
durai arasan
 
Php mysql training-in-mumbai
Php mysql training-in-mumbaiPhp mysql training-in-mumbai
Php mysql training-in-mumbai
vibrantuser
 

Similar to Php Tutorial (20)

PHP
PHPPHP
PHP
 
Prersentation
PrersentationPrersentation
Prersentation
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Php mysql training-in-mumbai
Php mysql training-in-mumbaiPhp mysql training-in-mumbai
Php mysql training-in-mumbai
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessor
 
Php
PhpPhp
Php
 
php basics
php basicsphp basics
php basics
 
Php
PhpPhp
Php
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
 
Php
PhpPhp
Php
 
Php basics
Php basicsPhp basics
Php basics
 
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
 
Php mysql training-in-mumbai
Php mysql training-in-mumbaiPhp mysql training-in-mumbai
Php mysql training-in-mumbai
 

Recently uploaded

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 

Recently uploaded (20)

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 

Php Tutorial

  • 1. PHP (Hypertext Preprocessor) -Gursharandeep kaur bajwa (CTIEMT) 100220314317
  • 2. IntroductionIntroduction  PHP is stands for ’Hypertext Preprocessor ’ used for making dynamic web pages and interactive web pages.  PHP is server side scripting language intented to help web developers build dynamic web pages.  PHP scripts are executed on the server.  PHP supports many databases (MySql ,Oracle,PostgreSQL,Generic ODBC etc).  PHP was created by Rasmus Lerdrof in 1995.  PHP originally stood for ”PERSONAL HOME PAGE”  PHP is an Open Source software.  PHP is free to download and use.
  • 3. PHP FilesPHP Files  PHP files can contain text, HTML Tags and scripts.  PHP files are returned to the browser as plain HTML  PHP files have a file extension of ”.php”. EXECUTION OF PHP PAGE
  • 4. “PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C,Java & Perl with a couple of unique PHP-specific features thrown in .The goal of the language is to allow web developers to write dynamically generated pages quickly. ”
  • 5. Brief History of PHPBrief History of PHP PHP (PHP: Hypertext Preprocessor) was created by Rasmus Lerdorf in 1994. It was initially developed for HTTP usage logging and server- side form generation in Unix  PHP 2 (1995) transformed the language into a Server-side embedded scripting language. Added database support, file uploads, variables, arrays, recursive functions, conditionals, iteration, regular expressions, etc.  PHP 3 (1998) added support for ODBC data sources, multiple platform support, email protocols (SNMP,IMAP), and new parser written by Zeev Suraski and Andi Gutmans .  PHP 4 (2000) became an independent component of the web server for added efficiency. The parser was renamed the Zend Engine. Many security features were added.
  • 6.  PHP 5 (2004) adds Zend Engine II with object oriented programming, robust XML support using the libxml2 library, SOAP extension for interoperability with Web Services, SQLite has been bundled with PHP
  • 7. PHP FeaturesPHP Features  Open source / Free software.  Cross Platform to develop, to deploy, and to use.  Power,Robust, Scalable.  Web development specific.  Can be Object Oriented.  It is faster to code and faster to execute.  Large, active developer community.  20 million websites  Support for PHP is free.  Great documentation in many language www.php.net/docs.php
  • 8. Why use PHP ?Why use PHP ? 1. Easy to use Code is embedded into HTML. The PHP code is enclosed in special start and end tags that allow you to jump into and out. <html> <head> <title>Example</title> </head>
  • 9. <body> <?php echo “Hi , I’m a PHP script! ”; ?> </body> </html>
  • 10. 2.Cross Platform Run on almost any web server on several Operating Systems. One of the strongest features is the wide range of supported databases. • Web Server : Apache, Microsoft IIS , Netscape Enterprise Server. • Operating Systems : Unix (Solaris,Linux),Mac OS, Window NT/98/2000/XP/2003. • Supported Databases : dBase,Empress,FilePro (read only), Hyperware, IBM DB2,InformixIngress,Frontbase,MySql,ODBC,Oracle etc.
  • 11. 3. Cost Benefits PHP is free. Open Source code means that the entire PHP community will contribute towards bug fixes. There are several add-on technologies (libraries) for PHP that are also free.
  • 12. DatatypesDatatypes  PHP stores whole numbers in a platform-dependent range.  This range is typically that of 32-bit signed integers. Unsigned integers are converted to signed values in certain situations.  Arrays can contain elements of any type that handle in PHP .  Including resources, objects, and even other arrays.  PHP also supports strings, which can be used with single quotes, double quotes, or heredoc syntax.
  • 13. What does PHP code look like?What does PHP code look like?  Structurally similar to C/C++  Supports procedural and object-oriented paradigm (to some degree)  All PHP statements end with a semi-colon  Each PHP script must be enclosed in the reserved PHP tag <?php … ?>
  • 14. Comments in PHPComments in PHP  Standard C, C++, and shell comment symbols // C++ and Java-style comment # Shell-style comments /* C-style comments These can span multiple lines */
  • 15. Variables in PHPVariables in PHP  PHP variables must begin with a “$” sign  Case-sensitive ($Foo != $foo != $fOo)  Global and locally-scoped variables -- Global variables can be used anywhere -- Local variables restricted to a function or class  Certain variable names reserved by PHP -- Form variables ($_POST, $_GET) -- Server variables ($_SERVER) -- Etc.
  • 16. Variable usageVariable usage <?php $foo = 25; // Numerical variable $bar = “Hello”; // String variable $foo = ($foo * 7); // Multiplies foo by 7 $bar = ($bar * 7); // Invalid expression ?>
  • 17. EchoEcho  The PHP command ‘echo’ is used to output the parameters passed to it --The typical usage for this is to send data to the client’s web-browser  Syntax -- void echo (string arg1 [, string argn...]) -- In practice, arguments are not passed in parentheses since echo is a language construct rather than an actual function
  • 18. Echo exampleEcho example  PHP scripts are stored as human-readable source code and are compiled on-the-fly to an internal format that can be executed by the PHP engine.  Code optimizers aim to reduce the runtime of the compiled code by reducing its size and making other changes that can reduce the execution time with the goal of improving performance. <?php $foo = 25; // Numerical variable $bar = “Hello”; // String variable echo $bar; // Outputs Hello echo $foo,$bar; // Outputs 25Hello echo “5x5=”,$foo; // Outputs 5x5=25 echo “5x5=$foo”; // Outputs 5x5=25 echo ‘5x5=$foo’; // Outputs 5x5=$foo ?>
  • 19. Arithmetic OperationsArithmetic Operations  $a - $b // subtraction  $a * $b // multiplication  $a / $b // division  $a += 5 // $a = $a+5 Also works for *= and /= <?php $a=15; $b=30; $total=$a+$b; Print $total; Print “<p><h1>$total</h1>”; // total is 45 ?>
  • 21. Escaping the CharacterEscaping the Character  If the string has a set of double quotation marks that must remain visible, use the [backslash] before the quotation marks to ignore and display them. <?php $heading=“”Computer Science””; Print $heading; ?> “Computer Science”
  • 22. PHP Control StructuresPHP Control Structures  Control Structures: Are the structures within a language that allow us to control the flow of execution through a program or script.  Grouped into conditional (branching) structures (e.g. if/else) and repetition structures (e.g. while loops).  Example if/else if/else statement: if ($foo == 0) { echo ‘The variable foo is equal to 0’; } else if (($foo > 0) && ($foo <= 5)) { echo ‘The variable foo is between 1 and 5’; } else { echo ‘The variable foo is equal to ‘.$foo; }
  • 23. If ... Else...If ... Else... If (condition) { Statements; } Else { Statement; } <?php If($user==“John”) { Print “Hello John.”; } Else { Print “You are not John.”; } ?> No THEN in PHP
  • 24. While LoopsWhile Loops While (condition) { Statements; } <?php $count=0; While($count<3) { Print “hello PHP. ”; $count += 1; // $count = $count + 1; // or // $count++; ?> hello PHP. hello PHP. hello PHP.
  • 25. Date DisplayDate Display $datedisplay=date(“yyyy/m/d”); Print $datedisplay; # If the date is April 1st , 2009 # It would display as 2009/4/1 $datedisplay=date(“l, F m, Y”); Print $datedisplay; # If the date is April 1st , 2009 # Wednesday, April 1, 2009 2009/4/1 Wednesday, April 1, 2009
  • 26. Month, Day & Date Format SymbolsMonth, Day & Date Format Symbols M Jan F January m 01 n 1 Day of Month d 01 Day of Month J 1 Day of Week l Monday Day of Week D Mon
  • 27. FunctionsFunctions  Functions MUST be defined before then can be called  Function headers are of the format -- Note that no return type is specified  Unlike variables, function names are not case sensitive (foo(…) == Foo(…) == FoO(…)) function functionName($arg_1, $arg_2, …, $arg_n)
  • 28. Functions exampleFunctions example <?php // This is a function function foo($arg_1, $arg_2) { $arg_2 = $arg_1 * $arg_2; return $arg_2; } $result_1 = foo(12, 3); // Store the function echo $result_1; // Outputs 36 echo foo(12, 3); // Outputs 36 ?>
  • 29. Include FilesInclude Files Include “opendb.php”; Include “closedb.php”; This inserts files; the code in files will be inserted into current code. Thiswill provide useful and protective means once you connect to a database, as well as for other repeated functions. Include (“footer.php”); The file footer.php might look like: <hr SIZE=11 NOSHADE WIDTH=“100%”> <i>Copyright © 2008-2010 KSU </i></font><br> <i>ALL RIGHTS RESERVED</i></font><br> <i>URL: http://www.kent.edu</i></font><br>
  • 30. PHP FormsPHP Forms  Access to the HTTP POST and GET data is simple in PHPAccess to the HTTP POST and GET data is simple in PHP  The global variables $_POST[] and $_GET[] contain the request dataThe global variables $_POST[] and $_GET[] contain the request data <?php if ($_POST["submit"]) echo "<h2>You clicked Submit!</h2>"; else if ($_POST["cancel"]) echo "<h2>You clicked Cancel!</h2>"; ?> <form action="form.php" method="post"> <input type="submit" name="submit" value="Submit"> <input type="submit" name="cancel" value="Cancel"> </form>
  • 31. What is a cookie ?What is a cookie ? A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests for a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.
  • 32. How To Create a Cookie?How To Create a Cookie?  The setcookie() function is used to create cookies. Note: The setcookie() function must appear BEFORE the <html> tag. setcookie(name, [value], [expire], [path], [domain], [secure]); This sets a cookie named "uname" - that expires after ten hours. <?php setcookie("uname", $name, time()+36000); ?> <html> <body> …
  • 33. How To Retrieve a Cookie Value?How To Retrieve a Cookie Value?  To access a cookie you just refer to the cookie name as a variable or use $_COOKIE array  Tip: Use the isset() function to find out if a cookie has been set. <html> <body> <?php if (isset($uname)) echo "Welcome " . $uname . "!<br />"; else echo "You are not logged in!<br />"; ?> </body> </html>
  • 34. How To Delete a Cookie ?How To Delete a Cookie ?  Cookies must be deleted with the same parameters as they were set with. If the value argument is an empty string (""), and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client.
  • 35. What is a Session?  The session support allows you to register arbitrary numbers of variables to be preserved across requests.  A visitor accessing your web site is assigned an unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.  Tip: Use the isset() function to find out if a cookie has been set.
  • 36. How to Create a Session ?  The session_start() function is used to create cookies. <?php session_start(); ?>
  • 37. How to Retrieve a Session Value ?  Register Session variable -- session_register('var1','var2',...); // will also create a session -- PS:Session variable will be created on using even if you will not register it!  Use it <?php session_start(); if (!isset($_SESSION['count'])) $_SESSION['count'] = 0; else $_SESSION['count']++; ?>
  • 38. Storing Session Data  The $_SESSION superglobal array can be used to store any session data. e.g. $_SESSION[‘name’] = $name; $_SESSION[‘age’] = $age;
  • 39. Reading Session Data Data is simply read back from the $_SESSION superglobal array. e.g. $_SESSION[‘name’] = $name; $_SESSION[‘age’] = $age;
  • 40. How to Delete a Session Value ?  session_unregister(´varname´); How to destroy a session:  session_destroy()
  • 41. PHP DATABASE INTERACTION IN FIVE STEPS 1) Create the Connection 2) Select the Database 3) Perform Database Query 4) Use Returned Data (if any) 5) Close Connection
  • 42. 1. Connect with MySQL RDBMS mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");
  • 43. 2. Connect with database mysql_select_db($dbName) or die("Unable to select database $dbName");
  • 44. 3. Perform Database Query Queries: Nearly all table interaction and management is done through queries: Basic information searches $query = "SELECT FirstName, LastName, DOB, Gender FROM Patients WHERE Gender = '$Gender‘ ORDER BY FirstName DESC"; $Patients = mysql_query($SQL); Editing, adding, and deleting records and tables $query = "INSERT INTO Patients (FirstName, LastName) VALUES('$firstName', '$lastName')"; $Patients = mysql_query($SQL);
  • 45. 4. Process Results (if any) • Many functions exist to work with database results mysql_num_rows() – Number of rows in the result set – Useful for iterating over result set mysql_fetch_array() – Returns a result row as an array – Can be associative or numeric or both (default) – $row = mysql_fetch_array($query); – $row[‘column name’] :: value comes from database row with specified column name
  • 46. Process Results Loop • Easy loop for processing results: $result = mysql_query($query; $num_rows = mysql_num_rows($query); for ($i=0; $i<$num_rows; $i++) { $row = mysql_fetch_array($result); // take action on database results here }
  • 47. 5. Closing Database Connection • mysql_close() – Closes database connection – Only works for connections opened with mysql_connect() – Connections opened with mysql_pconnect() ignore this call – Often not necessary to call this, as connections created by mysql_connect are closed at the end of the script anyway