SlideShare a Scribd company logo
1 of 15
CS Learning Centre
PHP Tutorial
Introduction
⇨ Based on PHP and MySQL Web
Development, Third Edition (Available as
CS eBook from Dal Library)
⇨ Other eBooks from Dal Library
⇨ Learning PHP 5
⇨ PHP Cookbook
⇨ For Online resources, google “PHP”
Table of Contents
⇨ Embedding PHP
⇨ Variables
⇨ Operators and Control Structures
⇨ Array
⇨ Function
⇨ Session Control (Using Cookie)
Embedding PHP in HTML
⇨ Insert PHP tag inside HTML file (with .php
extension
⇨ XML Style
<?php PHP statement; ?>
⇨ Short Style (Need to be enabled)
<? PHP statement; ?>
⇨ Script Style
<SCRIPT LANGUAGE='php'> PHP statement;
</SCRIPT>
⇨ ASP Style (Need to be enabled)
<% PHP statement; %>
⇨ Dynamic Content
function('argument');
⇨ Note: argument is in string
Variables
⇨ Do not require to declare variable type
⇨ Variable variables
$varname = 'tireqty';
$$varname = 5;
⇨ Constants
define('TIREPRICE', 100);
⇨ Accessing form variables (field=tireqty)
⇨ Short style (requires register_globals)
$tieryqty
⇨ Medium style
$_POST['tireqty'] or $_GET['tireqty']
⇨ Long style
$HTTP_POST_VARS['tireqty']
Operators and Control
Structures
⇨ Pretty much same as in other programming
languages (C, Java, etc.)
⇨ Break statements are also same (continue,
break), except it provides exit statement to
break out of the script
⇨ Alternative control structure syntex
if( $totalqty == 0):
echo 'You did not order anything on the previous
page!<br />';
exit;
endif;
Array
⇨ Create an array
$products = array ('Tires', 'Oil', 'Engine');
⇨ Automatically generate sequnces of
number, character
$numbers = range (1,10,2); //last parameter optional(Indicate step)
⇨ Accessing element
$products[0]
⇨ Array with different indices
$prices = array( 'Tires'=>100, 'Oil'=>10, 'Spark Plugs'=>4 );
⇨ Assign key and value to variables
list( $product, $price ) = each( $prices );
Array (Cont'd)
⇨ Multidimensional Array
($products[row][column]
$products = array( array( 'Code' => 'TIR',
'Description' => 'Tires',
'Price' => 100
),
array( 'Code' => 'OIL',
'Description' => 'Oil',
'Price' => 10
),
array( 'Code' => 'SPK',
'Description' => 'Spark Plugs',
'Price' =>4
)
);
Function
⇨ New function
function my_function()
{
echo 'My function was called';
}
⇨ Calling function
my_function();
Function (Cont'd)
⇨ Using argument
⇨ Should reset the argument if it is an array
⇨ The next command gets next element of arg
⇨ The current command gets current element
⇨ Ex.
function create_table2( $data, $border = 1, $cellpadding = 4, $cellspacing = 4 )
{
echo "<table border = $border cellpadding = $cellpadding"
." cellspacing = $cellspacing>";
reset($data);
$value = current($data);
while ($value)
{
echo "<tr><td>$value</td></tr>n";
$value = next($data);
}
echo '</table>';
}
Session Control (Using Cookie)
⇨ Manually setting Cookie in PHP
bool setcookie (string name [, string value [, int
expire [, string path
[, string domain [, int secure]]]]])
Ex. setcookie ('mycookie', 'value');
⇨ Using Cookie with Sessions
⇨ Get session cookie parameters
session_get_cookie_params()
⇨ Set session cookie parameters
session_set_cookie_params($lifetime, $path,
$domain [, $secure]);
Session Control (Cont'd)
⇨ Starting Session (Must be declared at the
beginning of the file)
session_start();
⇨ Registering Session variables
$_SESSION['myvar'] = 5;
⇨ Unsetting variables
⇨ Single variable
unset($_SESSION['myvar']);
⇨ All variables
$_SESSION=array();
⇨ Destroying session
session_destroy();
Session Control (Example)
⇨ Begin session
<?php
session_start();
$_SESSION['sess_var'] = "Hello world!";
echo 'The content of $_SESSION['sess_var'] is '
.$_SESSION['sess_var'].'<br />';
?>
<a href="page2.php">Next page</a>
Session Control (Example)
⇨ Get the variable and unset it
<?php
session_start();
echo 'The content of $_SESSION['sess_var'] is '
.$_SESSION['sess_var'].'<br />';
unset($_SESSION['sess_var']);
?>
<a href="page3.php">Next page</a>
Session Control (Example
⇨ End session
<?php
session_start();
echo 'The content of $_SESSION['sess_var'] is '
.$_SESSION['sess_var'].'<br />';
session_destroy();
?>

More Related Content

Similar to php tutorial.ppt

Power shell voor developers
Power shell voor developersPower shell voor developers
Power shell voor developersDennis Vroegop
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHPNat Weerawan
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requireTheCreativedev Blog
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207patter
 
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze..."Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...Mateusz Zalewski
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest UpdatesIftekhar Eather
 
Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)tompunk
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Developmentjsmith92
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesEric Poe
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricksFilip Golonka
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologyDaniel Knell
 
Михаил Крайнюк. Form api: ajax-commands
Михаил Крайнюк. Form api: ajax-commandsМихаил Крайнюк. Form api: ajax-commands
Михаил Крайнюк. Form api: ajax-commandsKsenia Rogachenko
 
Михаил Крайнюк. Form api: ajax-commands
Михаил Крайнюк. Form api: ajax-commandsМихаил Крайнюк. Form api: ajax-commands
Михаил Крайнюк. Form api: ajax-commandsDrupalSib
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of LithiumNate Abele
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Fabien Potencier
 
Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Fabien Potencier
 

Similar to php tutorial.ppt (20)

Power shell voor developers
Power shell voor developersPower shell voor developers
Power shell voor developers
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
SPL, not a bridge too far
SPL, not a bridge too farSPL, not a bridge too far
SPL, not a bridge too far
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
PHP pod mikroskopom
PHP pod mikroskopomPHP pod mikroskopom
PHP pod mikroskopom
 
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze..."Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
 
PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricks
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
Михаил Крайнюк. Form api: ajax-commands
Михаил Крайнюк. Form api: ajax-commandsМихаил Крайнюк. Form api: ajax-commands
Михаил Крайнюк. Form api: ajax-commands
 
Михаил Крайнюк. Form api: ajax-commands
Михаил Крайнюк. Form api: ajax-commandsМихаил Крайнюк. Form api: ajax-commands
Михаил Крайнюк. Form api: ajax-commands
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of Lithium
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
 
Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)
 

Recently uploaded

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 

Recently uploaded (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

php tutorial.ppt

  • 2. Introduction ⇨ Based on PHP and MySQL Web Development, Third Edition (Available as CS eBook from Dal Library) ⇨ Other eBooks from Dal Library ⇨ Learning PHP 5 ⇨ PHP Cookbook ⇨ For Online resources, google “PHP”
  • 3. Table of Contents ⇨ Embedding PHP ⇨ Variables ⇨ Operators and Control Structures ⇨ Array ⇨ Function ⇨ Session Control (Using Cookie)
  • 4. Embedding PHP in HTML ⇨ Insert PHP tag inside HTML file (with .php extension ⇨ XML Style <?php PHP statement; ?> ⇨ Short Style (Need to be enabled) <? PHP statement; ?> ⇨ Script Style <SCRIPT LANGUAGE='php'> PHP statement; </SCRIPT> ⇨ ASP Style (Need to be enabled) <% PHP statement; %> ⇨ Dynamic Content function('argument'); ⇨ Note: argument is in string
  • 5. Variables ⇨ Do not require to declare variable type ⇨ Variable variables $varname = 'tireqty'; $$varname = 5; ⇨ Constants define('TIREPRICE', 100); ⇨ Accessing form variables (field=tireqty) ⇨ Short style (requires register_globals) $tieryqty ⇨ Medium style $_POST['tireqty'] or $_GET['tireqty'] ⇨ Long style $HTTP_POST_VARS['tireqty']
  • 6. Operators and Control Structures ⇨ Pretty much same as in other programming languages (C, Java, etc.) ⇨ Break statements are also same (continue, break), except it provides exit statement to break out of the script ⇨ Alternative control structure syntex if( $totalqty == 0): echo 'You did not order anything on the previous page!<br />'; exit; endif;
  • 7. Array ⇨ Create an array $products = array ('Tires', 'Oil', 'Engine'); ⇨ Automatically generate sequnces of number, character $numbers = range (1,10,2); //last parameter optional(Indicate step) ⇨ Accessing element $products[0] ⇨ Array with different indices $prices = array( 'Tires'=>100, 'Oil'=>10, 'Spark Plugs'=>4 ); ⇨ Assign key and value to variables list( $product, $price ) = each( $prices );
  • 8. Array (Cont'd) ⇨ Multidimensional Array ($products[row][column] $products = array( array( 'Code' => 'TIR', 'Description' => 'Tires', 'Price' => 100 ), array( 'Code' => 'OIL', 'Description' => 'Oil', 'Price' => 10 ), array( 'Code' => 'SPK', 'Description' => 'Spark Plugs', 'Price' =>4 ) );
  • 9. Function ⇨ New function function my_function() { echo 'My function was called'; } ⇨ Calling function my_function();
  • 10. Function (Cont'd) ⇨ Using argument ⇨ Should reset the argument if it is an array ⇨ The next command gets next element of arg ⇨ The current command gets current element ⇨ Ex. function create_table2( $data, $border = 1, $cellpadding = 4, $cellspacing = 4 ) { echo "<table border = $border cellpadding = $cellpadding" ." cellspacing = $cellspacing>"; reset($data); $value = current($data); while ($value) { echo "<tr><td>$value</td></tr>n"; $value = next($data); } echo '</table>'; }
  • 11. Session Control (Using Cookie) ⇨ Manually setting Cookie in PHP bool setcookie (string name [, string value [, int expire [, string path [, string domain [, int secure]]]]]) Ex. setcookie ('mycookie', 'value'); ⇨ Using Cookie with Sessions ⇨ Get session cookie parameters session_get_cookie_params() ⇨ Set session cookie parameters session_set_cookie_params($lifetime, $path, $domain [, $secure]);
  • 12. Session Control (Cont'd) ⇨ Starting Session (Must be declared at the beginning of the file) session_start(); ⇨ Registering Session variables $_SESSION['myvar'] = 5; ⇨ Unsetting variables ⇨ Single variable unset($_SESSION['myvar']); ⇨ All variables $_SESSION=array(); ⇨ Destroying session session_destroy();
  • 13. Session Control (Example) ⇨ Begin session <?php session_start(); $_SESSION['sess_var'] = "Hello world!"; echo 'The content of $_SESSION['sess_var'] is ' .$_SESSION['sess_var'].'<br />'; ?> <a href="page2.php">Next page</a>
  • 14. Session Control (Example) ⇨ Get the variable and unset it <?php session_start(); echo 'The content of $_SESSION['sess_var'] is ' .$_SESSION['sess_var'].'<br />'; unset($_SESSION['sess_var']); ?> <a href="page3.php">Next page</a>
  • 15. Session Control (Example ⇨ End session <?php session_start(); echo 'The content of $_SESSION['sess_var'] is ' .$_SESSION['sess_var'].'<br />'; session_destroy(); ?>