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 (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

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

Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllersmussawir20
 
Php Calling Operators
Php Calling OperatorsPhp Calling Operators
Php Calling Operatorsmussawir20
 
Database Design Process
Database Design ProcessDatabase Design Process
Database Design Processmussawir20
 
Php Simple Xml
Php Simple XmlPhp Simple Xml
Php Simple Xmlmussawir20
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressionsmussawir20
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functionsmussawir20
 
Php File Operations
Php File OperationsPhp File Operations
Php File Operationsmussawir20
 
Php Error Handling
Php Error HandlingPhp Error Handling
Php Error Handlingmussawir20
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arraysmussawir20
 
Javascript Oop
Javascript OopJavascript Oop
Javascript Oopmussawir20
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)mussawir20
 

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

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Dernier (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

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.