SlideShare uma empresa Scribd logo
1 de 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]

Mais conteúdo relacionado

Mais procurados

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
 

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

Semelhante a 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
 

Semelhante a 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
 

Mais 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
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

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.