SlideShare une entreprise Scribd logo
1  sur  14
Session and Cookies
SESSION ,[object Object],[object Object],[object Object],[object Object],[object Object]
Example 1 ,[object Object],[object Object],[object Object],[object Object]
<?php  // initialize a session  session_start ();  ?>  <html>  <head></head>  <body>  <?php  if (!isset( $_SESSION [ 'name' ]) && !isset( $_POST [ 'name' ])) {       // if no data, print the form  ?>      <form action=&quot; <?php  echo  $_SERVER [ 'PHP_SELF' ] ?> &quot; method=&quot;post&quot;>          <input type=&quot;text&quot; name=&quot;name&quot;>          <input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Enter your name&quot;>      </form>  <?php  }  else if (!isset( $_SESSION [ 'name' ]) && isset( $_POST [ 'name' ])) {       // if a session does not exist but the form has been submitted      // check to see if the form has all required values      // create a new session       if (!empty( $_POST [ 'name' ])) {           $_SESSION [ 'name' ] =  $_POST [ 'name' ];           $_SESSION [ 'start' ] =  time ();          echo  &quot;Welcome, &quot;  .  $_POST [ 'name' ] .  &quot;. A new session has been activated for you. Click <a href=&quot;  .  $_SERVER [ 'PHP_SELF' ] .  &quot;>here</a> to refresh the page.&quot; ;      }      else {          echo  &quot;ERROR: Please enter your name!&quot; ;      }  }  else if (isset( $_SESSION [ 'name' ])) {       // if a previous session exists      // calculate elapsed time since session start and now       echo  &quot;Welcome back, &quot;  .  $_SESSION [ 'name' ] .  &quot;. This session was activated &quot;  .  round (( time () -  $_SESSION [ 'start' ]) /  60 ) .  &quot; minute(s) ago. Click <a href=&quot;  .  $_SERVER [ 'PHP_SELF' ] .  &quot;>here</a> to refresh the page.&quot; ;  }  ?>  </body>  </html>
Continue… ,[object Object],[object Object],[object Object],[object Object]
Example 2 ,[object Object],[object Object],[object Object],[object Object]
Example 3 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Cookies ,[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Continue…
[object Object],Form and Function
Continue… ,[object Object]
Continue… ,[object Object],[object Object],[object Object]
Remove a cookies ,[object Object],[object Object],[object Object],[object Object]
Conclusion ,[object Object],[object Object],[object Object]

Contenu connexe

Tendances

Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
Sukrit Gupta
 
Cookie & Session In ASP.NET
Cookie & Session In ASP.NETCookie & Session In ASP.NET
Cookie & Session In ASP.NET
ShingalaKrupa
 
Web Cookies
Web CookiesWeb Cookies
Web Cookies
apwebco
 
Cookies: HTTP state management mechanism
Cookies: HTTP state management mechanismCookies: HTTP state management mechanism
Cookies: HTTP state management mechanism
Jivan Nepali
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
salissal
 

Tendances (20)

Session and Cookies
Session and CookiesSession and Cookies
Session and Cookies
 
Sessions in php
Sessions in php Sessions in php
Sessions in php
 
PHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and SessionsPHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and Sessions
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introduction
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Cookie & Session In ASP.NET
Cookie & Session In ASP.NETCookie & Session In ASP.NET
Cookie & Session In ASP.NET
 
java Cookies
java Cookiesjava Cookies
java Cookies
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Cookies and Session
Cookies and SessionCookies and Session
Cookies and Session
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erick
 
PHP Cookies, Sessions and Authentication
PHP Cookies, Sessions and AuthenticationPHP Cookies, Sessions and Authentication
PHP Cookies, Sessions and Authentication
 
PHP - Getting good with cookies
PHP - Getting good with cookiesPHP - Getting good with cookies
PHP - Getting good with cookies
 
Web Cookies
Web CookiesWeb Cookies
Web Cookies
 
ASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and CookiesASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and Cookies
 
Cookies: HTTP state management mechanism
Cookies: HTTP state management mechanismCookies: HTTP state management mechanism
Cookies: HTTP state management mechanism
 
Sessions n cookies
Sessions n cookiesSessions n cookies
Sessions n cookies
 
Sessions and cookies in php
Sessions and cookies in phpSessions and cookies in php
Sessions and cookies in php
 
Internet Cookies
Internet CookiesInternet Cookies
Internet Cookies
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 

Similaire à Php Sessoins N Cookies

Php Basic Security
Php Basic SecurityPhp Basic Security
Php Basic Security
mussawir20
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
mussawir20
 
Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0
Cathie101
 
Php Security3895
Php Security3895Php Security3895
Php Security3895
Aung Khant
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In Php
Harit Kothari
 
Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8
Tatsuhiko Miyagawa
 

Similaire à Php Sessoins N Cookies (20)

Php 3 1
Php 3 1Php 3 1
Php 3 1
 
Manish
ManishManish
Manish
 
Php Basic Security
Php Basic SecurityPhp Basic Security
Php Basic Security
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To Lamp
 
Ph
PhPh
Ph
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
 
Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
SlideShare Instant
SlideShare InstantSlideShare Instant
SlideShare Instant
 
SlideShare Instant
SlideShare InstantSlideShare Instant
SlideShare Instant
 
Php security3895
Php security3895Php security3895
Php security3895
 
PHP Security
PHP SecurityPHP Security
PHP Security
 
4.4 PHP Session
4.4 PHP Session4.4 PHP Session
4.4 PHP Session
 
Php Security3895
Php Security3895Php Security3895
Php Security3895
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In Php
 
Web development
Web developmentWeb development
Web development
 
Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
Php - Getting good with session
Php - Getting good with sessionPhp - Getting good with session
Php - Getting good with session
 

Plus de mussawir20 (20)

Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
 
Php Calling Operators
Php Calling OperatorsPhp Calling Operators
Php Calling Operators
 
Database Design Process
Database Design ProcessDatabase Design Process
Database Design Process
 
Php Simple Xml
Php Simple XmlPhp Simple Xml
Php Simple Xml
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressions
 
Php Sq Lite
Php Sq LitePhp Sq Lite
Php Sq Lite
 
Php Rss
Php RssPhp Rss
Php Rss
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
Php Oop
Php OopPhp Oop
Php Oop
 
Php My Sql
Php My SqlPhp My Sql
Php My Sql
 
Php File Operations
Php File OperationsPhp File Operations
Php File Operations
 
Php Error Handling
Php Error HandlingPhp Error Handling
Php Error Handling
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
 
Javascript Oop
Javascript OopJavascript Oop
Javascript Oop
 
Html
HtmlHtml
Html
 
Javascript
JavascriptJavascript
Javascript
 
Object Range
Object RangeObject Range
Object Range
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)
 
Date
DateDate
Date
 
Prototype js
Prototype jsPrototype js
Prototype js
 

Dernier

Dernier (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Php Sessoins N Cookies

  • 2.
  • 3.
  • 4. <?php // initialize a session session_start (); ?> <html> <head></head> <body> <?php if (!isset( $_SESSION [ 'name' ]) && !isset( $_POST [ 'name' ])) {      // if no data, print the form ?>     <form action=&quot; <?php echo $_SERVER [ 'PHP_SELF' ] ?> &quot; method=&quot;post&quot;>         <input type=&quot;text&quot; name=&quot;name&quot;>         <input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Enter your name&quot;>     </form> <?php } else if (!isset( $_SESSION [ 'name' ]) && isset( $_POST [ 'name' ])) {      // if a session does not exist but the form has been submitted     // check to see if the form has all required values     // create a new session      if (!empty( $_POST [ 'name' ])) {          $_SESSION [ 'name' ] = $_POST [ 'name' ];          $_SESSION [ 'start' ] = time ();         echo &quot;Welcome, &quot; . $_POST [ 'name' ] . &quot;. A new session has been activated for you. Click <a href=&quot; . $_SERVER [ 'PHP_SELF' ] . &quot;>here</a> to refresh the page.&quot; ;     }     else {         echo &quot;ERROR: Please enter your name!&quot; ;     } } else if (isset( $_SESSION [ 'name' ])) {      // if a previous session exists     // calculate elapsed time since session start and now      echo &quot;Welcome back, &quot; . $_SESSION [ 'name' ] . &quot;. This session was activated &quot; . round (( time () - $_SESSION [ 'start' ]) / 60 ) . &quot; minute(s) ago. Click <a href=&quot; . $_SERVER [ 'PHP_SELF' ] . &quot;>here</a> to refresh the page.&quot; ; } ?> </body> </html>
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.