SlideShare a Scribd company logo
PHP BASIC PRESENTATION
PHP
➢What is open source? Why do people prefer using open source software?
➢What is PHP?
➢What is PHP File?
➢What Can PHP Do?
➢Why PHP?
➢Who Uses PHP?History.
OPEN SOURCE
● Open source software is different. Its authors make its source code available to
others who would like to view that code, copy it, learn from it, alter it, or share it.
● It means that anyone should be able to modify the source code to suit his or her
needs.
What is PHP?
● PHP: Hypertext Preprocessor
● PHP is a widely-used, open source scripting language
● PHP is free to download and use.
● It is deep enough to run the largest social network (Facebook)!
PHP BASIC PRESENTATION
What is a PHP File?
● PHP files can contain text, HTML, CSS, JavaScript, and PHP code.
● PHP code are executed on the server, and the result is returned to the browser as
plain HTML.
● PHP files have extension ".php"
What Can PHP Do?
● PHP can generate dynamic page content
● PHP can create, open, read, write, delete, and close files on the server
● PHP can collect form data
● PHP can add, delete, modify data in your database
Why PHP?
● PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
● PHP is compatible with almost all servers used today (Apache,IIS,etc).
● PHP supports a wide range of databases
● PHP is free. Download it from the official PHP resource: www.php.net
● PHP is easy to learn and runs efficiently on the server side
WHO USES PHP?
PHP HISTORY
● Created by Rusmus Lerdorf
● PHP/FI 1.0 relesed in 1995
● PHP/FI 2.0 relesed in 1997
● PHP 3.0 relesed in 1998
● PHP 4.0 relesed in 2005
● PHP 5.0 relesed in 2009
● PHP 7.0 relesed in 2014
INSTALLATION
INSTALLATION
INSTALLATION
INSTALLATION
PHP BASIC
● Create New Folder within wamp/www/folder with the name you want to
give your project.
● E.G. c:wampwwwmyproject.
● Open your Browser and type localhost/myproject.
PHP SYNTAX
● Each php script must be enclosed with revered php tags
● <?php
...code
● ?>
● All php statements end with semi-colon. ;
PHP SYNTAX
● Each php script must be enclosed with revered php tags
● <?php
...code
● ?>
● All php statements end with semi-colon. ;
PHP BASIC PRESENTATION
Commenting
● // comment a single line
● # comment single line-shell style
● /* comment multiple
lines */
Echo Command
● The simple use of echo command is print a string as a argument in php.
● <?php
echo “HELLO WORLD” ;
?>
● Use n for new line & <br/> for new line
echo “line 1 n”;
echo “line 2”; &
echo “line1 <br/>”;
echo “line 2”;
Out put = line1 line 2 (n).
Out put of <br/>= line 1
Line 2
Variables
● Variables are identified and define by prefixing theier name with dollor sign.
● E.G $var1,$var2
● Variables may contain .(letter,underscore,number or dash) there should be no
space.
● Variable name are case-sensitive.
● $thisVar,$ThisvAr
Example of Variable
● $items
● $Items
● $_blog
● $product3
● $this-var
● $this_var
● $_bookPage
Variable variables
● $varName = ”age”;
● $$varName = “20”;
● This is exactlly equvivalent to
● $age = 20;
Constants
● Constants are define with difine() function
● E.G : define(“variable1”,”value”);
● Constants name follow same rule as a variable name.
● Valid constant
define(“firstname”,”a”);
define(“last_name”,”b”);
define(“_1bookprice”,”22”);
define(“USER”,”Modi”);
echo “Welcome “. USER;
OUT PUT: Welcome Modi
Data Types
● boolean :A value that can only either be true or false
● Int :A signed numeric integer value
● float : A signed floating-point value
● string : A collection of binary data
● Null is a special value that indicates no value.
● Arrays are containers of ordered data elements
● Objects are containers of both data and code
Define Data Types
● $int_var = 12345; Integer
● $temperature = 56.89; Floating Point
● $first_double = 123.456; Double
● TRUE=1, FALSE=0 Boolean
● $name = “abrakadabra” String
Operators
● Assignment (x = y,x += y, x -= y, x *= y, x /= y, x %= y)
● Arithmetic (+, - ,* ,/ ,%)
● Comparison (==,===,!=,<>,!==,>,<,>=,<=)
● Logical (and, or,xor,&&,||,!)
● String (. , .=)
Control Structures
● Conditional Control Structures
● If
● If else
● Switch
● Loops
● For
● while
● Do while
Errors and Error Management
Compile-time errors Detected by parser while compiling a
script. Cannot be trapped within the script
itself.
Fatal errors Halt the execution of a script. Cannot be
trapped.
Recoverable errors Represent significant failures but can be
handled in a safe way.
Warnings Recoverable errors that indicate a run-time
fault. Does not halt execution.
Notices Indicates that an error condition has
occurred but is not necessarily significant.
Does not halt script execution
functions
● A function is a block of statements that can be used repeatedly in a program.
● A function will not execute immediately when a page loads.
● A function will be executed by a call to the function.
● Syntax
function functionName() {
code to be executed;
}
Example of function
● <?php
function writeMsg() {
echo "Hello world!";
}
writeMsg(); // call the function
?>
● Out put : Hello World!
Array
● An array stores multiple values in one single variable: array();
<?php
$cars = array("Xylo", "BMW", "Swift");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>
● Out put : I like Xylo, BMW and Swift.
DataBase Connection (db)
//get connect to mysql
$link = mysql_connect($host,$username,$password);
//check for connection
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully <br/>';
$database='learndb';
if(mysql_select_db($database))
{ echo &quot;we are working with database: &quot;.$database;
} else {
echo &quot;There is some error: &quot;.mysql_error(); die();
}
//close the DB connection
mysql_close($link); ?>
Output: Connected successfully we are working with database: learndb
How to select values from MySQL tables
● Function : mysql_query($sql)
● Description :Send a MySQL query Syntax :resource
● mysql_query ( string $query [, resource $link_identifier ] )
● Example : Add following code before
● mysql_close($link) statement.
● //Start Querying table
● $selectSQL='select * from employee';
● $resultSet=mysql_query($selectSQL);
● echo &quot;<table border='1'>&quot;; echo
&quot;<tr><td><b>Name</b></td><td><b>Department</b></td>
● <td><b>Designation</b></td></tr>&quot;;
Session
● you work with an application, you open it, do some changes, and then you
close it. This is much like a Session. The computer knows who you are. It
knows when you start the application and when you end. But on the internet
there is one problem: the web server does not know who you are or what
you do, because the HTTP address doesn't maintain state.
● Session variables solve this problem by storing user information to be used
across multiple pages (e.g. username, favorite color, etc). By default,
session variables last until the user closes the browser.
● So; Session variables hold information about one single user, and are
available to all pages in one application.
Session
● A session is started with the session_start() function.
● <?php //Start the session
session_start();
?>
● <html><body>
<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>
</body></html>
What is a Cookie?
● A cookie is often used to identify a user. A cookie is a small file that the
server embeds on the user's computer. Each time the same computer
requests a page with a browser, it will send the cookie too. With PHP, you
can both create and retrieve cookie values.
● setcookie(name, value, expire, path, domain, secure, httponly);
Cookie
●
Cookies are text files stored on the client computer and they are kept of use
tracking purpose. PHP transparently supports HTTP cookies.
● Server script sends a set of cookies to the browser. For example name, age, or
identification number etc.
● Browser stores this information on local machine for future use
● When next time browser sends any request to web server then it sends those cookies
information to the server and server uses that information to identify the user.
GET & POST
● The GET method sends the encoded user information appended to the page
request. The page and the encoded information are separated by the ?
Character.
● http://www.test.com/index.htm?name1=value1&name2=value2
● The GET method produces a long string that appears in your server logs, in
the browser's Location: box.
● The GET method is restricted to send upto 1024 characters only.
● Never use GET method if you have password or other sensitive information
to be sent to the server.
● GET can't be used to send binary data, like images or word documents, to
the server.
● The data sent by GET method can be accessed using QUERY_STRING
environment variable.
GET & POST
● The POST method transfers information via HTTP headers. The
information is encoded as described in case of GET method and put into a
header called QUERY_STRING.
● POST requests are never cached
● POST requests do not remain in the browser history
● POST requests cannot be bookmarked
● POST requests have no restrictions on data length
● <?php
● if( $_POST["name"] || $_POST["age"] )
● {
● echo "Welcome ". $_POST['name']. "<br />";
● echo "You are ". $_POST['age']. " years old.";
● exit();
● }
● ?>
● <html>
● <body>
● <form action="<?php $_PHP_SELF ?>" method="POST">
● Name: <input type="text" name="name" />
● Age: <input type="text" name="age" />
● <input type="submit" />
● </form>
● </body>
● </html>
PHP FRAME WORKS
● Joomla
● Wordpress
● Zend cart
● Cake PHP
● Drupal
● Smarty
● Magento
● YII
PHP BASIC PRESENTATION

More Related Content

PPTX
Introduction to php
Taha Malampatti
 
PDF
Introduction to php web programming - get and post
baabtra.com - No. 1 supplier of quality freshers
 
PDF
A History of PHP
Xinchen Hui
 
PPTX
Introduction to PHP
Collaboration Technologies
 
PPT
Php Presentation
Manish Bothra
 
PPTX
PHP Hypertext Preprocessor
adeel990
 
PPTX
PHP in one presentation
Milad Rahimi
 
PPTX
PHP Function
Reber Novanta
 
Introduction to php
Taha Malampatti
 
Introduction to php web programming - get and post
baabtra.com - No. 1 supplier of quality freshers
 
A History of PHP
Xinchen Hui
 
Introduction to PHP
Collaboration Technologies
 
Php Presentation
Manish Bothra
 
PHP Hypertext Preprocessor
adeel990
 
PHP in one presentation
Milad Rahimi
 
PHP Function
Reber Novanta
 

What's hot (19)

PPT
PHP Tutorials
Yuriy Krapivko
 
PPT
PHP complete reference with database concepts for beginners
Mohammed Mushtaq Ahmed
 
PPT
Introduction To PHP
Shweta A
 
PPT
What Is Php
AVC
 
PPT
Overview of PHP and MYSQL
Deblina Chowdhury
 
PPTX
PHP FUNCTIONS
Zeeshan Ahmed
 
PPT
Class 6 - PHP Web Programming
Ahmed Swilam
 
PPT
Php intro
Jennie Gajjar
 
PDF
Introduction to PHP
Bradley Holt
 
PPT
01 Php Introduction
Geshan Manandhar
 
PDF
Security in php
Jalpesh Vasa
 
PDF
Lean Php Presentation
Alan Pinstein
 
PPTX
PHP language presentation
Annujj Agrawaal
 
PPTX
Loops PHP 04
mohamedsaad24
 
PPT
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
PPTX
Php presentation
Helen Pitlick
 
PDF
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
PPT
Php hypertext pre-processor
Siddique Ibrahim
 
PHP Tutorials
Yuriy Krapivko
 
PHP complete reference with database concepts for beginners
Mohammed Mushtaq Ahmed
 
Introduction To PHP
Shweta A
 
What Is Php
AVC
 
Overview of PHP and MYSQL
Deblina Chowdhury
 
PHP FUNCTIONS
Zeeshan Ahmed
 
Class 6 - PHP Web Programming
Ahmed Swilam
 
Php intro
Jennie Gajjar
 
Introduction to PHP
Bradley Holt
 
01 Php Introduction
Geshan Manandhar
 
Security in php
Jalpesh Vasa
 
Lean Php Presentation
Alan Pinstein
 
PHP language presentation
Annujj Agrawaal
 
Loops PHP 04
mohamedsaad24
 
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
Php presentation
Helen Pitlick
 
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
Php hypertext pre-processor
Siddique Ibrahim
 
Ad

Similar to PHP BASIC PRESENTATION (20)

PPT
php 1
tumetr1
 
PPTX
Unit 4-6 sem 7 Web Technologies.pptx
prathameshp9922
 
PPTX
introduction to php and its uses in daily
vishal choudhary
 
PPT
Php mysql
Abu Bakar
 
PPT
Php mysql
Ajit Yadav
 
PPTX
Introduction to webprogramming using PHP and MySQL
anand raj
 
PDF
WT_PHP_PART1.pdf
HambardeAtharva
 
PPT
Php basic for vit university
Mandakini Kumari
 
PPT
PHP and MySQL
Sanketkumar Biswas
 
PPT
Php Tutorial
SHARANBAJWA
 
PPTX
Php unit i
BagavathiLakshmi
 
PDF
Lecture2_IntroductionToPHP_Spring2023.pdf
ShaimaaMohamedGalal
 
PPTX
Ch1(introduction to php)
Chhom Karath
 
PPTX
Php Unit 1
team11vgnt
 
PPT
PHP
sometech
 
php 1
tumetr1
 
Unit 4-6 sem 7 Web Technologies.pptx
prathameshp9922
 
introduction to php and its uses in daily
vishal choudhary
 
Php mysql
Abu Bakar
 
Php mysql
Ajit Yadav
 
Introduction to webprogramming using PHP and MySQL
anand raj
 
WT_PHP_PART1.pdf
HambardeAtharva
 
Php basic for vit university
Mandakini Kumari
 
PHP and MySQL
Sanketkumar Biswas
 
Php Tutorial
SHARANBAJWA
 
Php unit i
BagavathiLakshmi
 
Lecture2_IntroductionToPHP_Spring2023.pdf
ShaimaaMohamedGalal
 
Ch1(introduction to php)
Chhom Karath
 
Php Unit 1
team11vgnt
 
Ad

Recently uploaded (20)

PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PPTX
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PPTX
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PDF
Become an Agentblazer Champion Challenge
Dele Amefo
 
PPTX
TestNG for Java Testing and Automation testing
ssuser0213cb
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PPTX
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
PDF
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PDF
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PDF
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
Q-Advise
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
Become an Agentblazer Champion Challenge
Dele Amefo
 
TestNG for Java Testing and Automation testing
ssuser0213cb
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
Presentation about variables and constant.pptx
kr2589474
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
Q-Advise
 

PHP BASIC PRESENTATION

  • 2. PHP ➢What is open source? Why do people prefer using open source software? ➢What is PHP? ➢What is PHP File? ➢What Can PHP Do? ➢Why PHP? ➢Who Uses PHP?History.
  • 3. OPEN SOURCE ● Open source software is different. Its authors make its source code available to others who would like to view that code, copy it, learn from it, alter it, or share it. ● It means that anyone should be able to modify the source code to suit his or her needs.
  • 4. What is PHP? ● PHP: Hypertext Preprocessor ● PHP is a widely-used, open source scripting language ● PHP is free to download and use. ● It is deep enough to run the largest social network (Facebook)!
  • 6. What is a PHP File? ● PHP files can contain text, HTML, CSS, JavaScript, and PHP code. ● PHP code are executed on the server, and the result is returned to the browser as plain HTML. ● PHP files have extension ".php"
  • 7. What Can PHP Do? ● PHP can generate dynamic page content ● PHP can create, open, read, write, delete, and close files on the server ● PHP can collect form data ● PHP can add, delete, modify data in your database
  • 8. Why PHP? ● PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) ● PHP is compatible with almost all servers used today (Apache,IIS,etc). ● PHP supports a wide range of databases ● PHP is free. Download it from the official PHP resource: www.php.net ● PHP is easy to learn and runs efficiently on the server side
  • 10. PHP HISTORY ● Created by Rusmus Lerdorf ● PHP/FI 1.0 relesed in 1995 ● PHP/FI 2.0 relesed in 1997 ● PHP 3.0 relesed in 1998 ● PHP 4.0 relesed in 2005 ● PHP 5.0 relesed in 2009 ● PHP 7.0 relesed in 2014
  • 15. PHP BASIC ● Create New Folder within wamp/www/folder with the name you want to give your project. ● E.G. c:wampwwwmyproject. ● Open your Browser and type localhost/myproject.
  • 16. PHP SYNTAX ● Each php script must be enclosed with revered php tags ● <?php ...code ● ?> ● All php statements end with semi-colon. ;
  • 17. PHP SYNTAX ● Each php script must be enclosed with revered php tags ● <?php ...code ● ?> ● All php statements end with semi-colon. ;
  • 19. Commenting ● // comment a single line ● # comment single line-shell style ● /* comment multiple lines */
  • 20. Echo Command ● The simple use of echo command is print a string as a argument in php. ● <?php echo “HELLO WORLD” ; ?> ● Use n for new line & <br/> for new line echo “line 1 n”; echo “line 2”; & echo “line1 <br/>”; echo “line 2”; Out put = line1 line 2 (n). Out put of <br/>= line 1 Line 2
  • 21. Variables ● Variables are identified and define by prefixing theier name with dollor sign. ● E.G $var1,$var2 ● Variables may contain .(letter,underscore,number or dash) there should be no space. ● Variable name are case-sensitive. ● $thisVar,$ThisvAr
  • 22. Example of Variable ● $items ● $Items ● $_blog ● $product3 ● $this-var ● $this_var ● $_bookPage
  • 23. Variable variables ● $varName = ”age”; ● $$varName = “20”; ● This is exactlly equvivalent to ● $age = 20;
  • 24. Constants ● Constants are define with difine() function ● E.G : define(“variable1”,”value”); ● Constants name follow same rule as a variable name. ● Valid constant define(“firstname”,”a”); define(“last_name”,”b”); define(“_1bookprice”,”22”); define(“USER”,”Modi”); echo “Welcome “. USER; OUT PUT: Welcome Modi
  • 25. Data Types ● boolean :A value that can only either be true or false ● Int :A signed numeric integer value ● float : A signed floating-point value ● string : A collection of binary data ● Null is a special value that indicates no value. ● Arrays are containers of ordered data elements ● Objects are containers of both data and code
  • 26. Define Data Types ● $int_var = 12345; Integer ● $temperature = 56.89; Floating Point ● $first_double = 123.456; Double ● TRUE=1, FALSE=0 Boolean ● $name = “abrakadabra” String
  • 27. Operators ● Assignment (x = y,x += y, x -= y, x *= y, x /= y, x %= y) ● Arithmetic (+, - ,* ,/ ,%) ● Comparison (==,===,!=,<>,!==,>,<,>=,<=) ● Logical (and, or,xor,&&,||,!) ● String (. , .=)
  • 28. Control Structures ● Conditional Control Structures ● If ● If else ● Switch ● Loops ● For ● while ● Do while
  • 29. Errors and Error Management Compile-time errors Detected by parser while compiling a script. Cannot be trapped within the script itself. Fatal errors Halt the execution of a script. Cannot be trapped. Recoverable errors Represent significant failures but can be handled in a safe way. Warnings Recoverable errors that indicate a run-time fault. Does not halt execution. Notices Indicates that an error condition has occurred but is not necessarily significant. Does not halt script execution
  • 30. functions ● A function is a block of statements that can be used repeatedly in a program. ● A function will not execute immediately when a page loads. ● A function will be executed by a call to the function. ● Syntax function functionName() { code to be executed; }
  • 31. Example of function ● <?php function writeMsg() { echo "Hello world!"; } writeMsg(); // call the function ?> ● Out put : Hello World!
  • 32. Array ● An array stores multiple values in one single variable: array(); <?php $cars = array("Xylo", "BMW", "Swift"); echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . "."; ?> ● Out put : I like Xylo, BMW and Swift.
  • 33. DataBase Connection (db) //get connect to mysql $link = mysql_connect($host,$username,$password); //check for connection if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully <br/>'; $database='learndb'; if(mysql_select_db($database)) { echo &quot;we are working with database: &quot;.$database; } else { echo &quot;There is some error: &quot;.mysql_error(); die(); } //close the DB connection mysql_close($link); ?> Output: Connected successfully we are working with database: learndb
  • 34. How to select values from MySQL tables ● Function : mysql_query($sql) ● Description :Send a MySQL query Syntax :resource ● mysql_query ( string $query [, resource $link_identifier ] ) ● Example : Add following code before ● mysql_close($link) statement. ● //Start Querying table ● $selectSQL='select * from employee'; ● $resultSet=mysql_query($selectSQL); ● echo &quot;<table border='1'>&quot;; echo &quot;<tr><td><b>Name</b></td><td><b>Department</b></td> ● <td><b>Designation</b></td></tr>&quot;;
  • 35. Session ● you work with an application, you open it, do some changes, and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are or what you do, because the HTTP address doesn't maintain state. ● Session variables solve this problem by storing user information to be used across multiple pages (e.g. username, favorite color, etc). By default, session variables last until the user closes the browser. ● So; Session variables hold information about one single user, and are available to all pages in one application.
  • 36. Session ● A session is started with the session_start() function. ● <?php //Start the session session_start(); ?> ● <html><body> <?php // Set session variables $_SESSION["favcolor"] = "green"; $_SESSION["favanimal"] = "cat"; echo "Session variables are set."; ?> </body></html>
  • 37. What is a Cookie? ● A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values. ● setcookie(name, value, expire, path, domain, secure, httponly);
  • 38. Cookie ● Cookies are text files stored on the client computer and they are kept of use tracking purpose. PHP transparently supports HTTP cookies. ● Server script sends a set of cookies to the browser. For example name, age, or identification number etc. ● Browser stores this information on local machine for future use ● When next time browser sends any request to web server then it sends those cookies information to the server and server uses that information to identify the user.
  • 39. GET & POST ● The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? Character. ● http://www.test.com/index.htm?name1=value1&name2=value2 ● The GET method produces a long string that appears in your server logs, in the browser's Location: box. ● The GET method is restricted to send upto 1024 characters only. ● Never use GET method if you have password or other sensitive information to be sent to the server. ● GET can't be used to send binary data, like images or word documents, to the server. ● The data sent by GET method can be accessed using QUERY_STRING environment variable.
  • 40. GET & POST ● The POST method transfers information via HTTP headers. The information is encoded as described in case of GET method and put into a header called QUERY_STRING. ● POST requests are never cached ● POST requests do not remain in the browser history ● POST requests cannot be bookmarked ● POST requests have no restrictions on data length
  • 41. ● <?php ● if( $_POST["name"] || $_POST["age"] ) ● { ● echo "Welcome ". $_POST['name']. "<br />"; ● echo "You are ". $_POST['age']. " years old."; ● exit(); ● } ● ?> ● <html> ● <body> ● <form action="<?php $_PHP_SELF ?>" method="POST"> ● Name: <input type="text" name="name" /> ● Age: <input type="text" name="age" /> ● <input type="submit" /> ● </form> ● </body> ● </html>
  • 42. PHP FRAME WORKS ● Joomla ● Wordpress ● Zend cart ● Cake PHP ● Drupal ● Smarty ● Magento ● YII