• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Presentation  Sessions &  Cookies PHP 5
 

Presentation Sessions & Cookies PHP 5

on

  • 8,632 views

This is a Presentation for PHP5 for Sessions and Cookies for Basic Users

This is a Presentation for PHP5 for Sessions and Cookies for Basic Users

Statistics

Views

Total Views
8,632
Views on SlideShare
8,597
Embed Views
35

Actions

Likes
2
Downloads
210
Comments
0

2 Embeds 35

http://www.slideshare.net 34
http://www.slashdocs.com 1

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Presentation  Sessions &  Cookies PHP 5 Presentation Sessions & Cookies PHP 5 Presentation Transcript

    • Sessions and Cookies
    • How to maintain state in a stateless web
    • What is meant by state?
      • To maintain state means the ability to retain values of variables and to keep track of users who are logged into the system.
    • Methods for maintaining state
      • Cookies
      • Sessions
      • Passing [hidden] variables
    • What is a cookie?
      • Cookies are simple text strings of the form of name=value which are stored persistently on the client’s machine.
      • A URL is stored with each cookie and it is used by the browser to determine whether it should send the cookie to the web server.
    • Cookie Example
      • <?php
      • $count++;
      • setCookie(“count”, $count);
      • ?>
      • Welcome! You’ve seen this site
      • <?php print($count . ($count == 1 ? “ time!” : “ times!”)); ?>
    • Common Pitfalls
      • Can’t call setCookie() after output has been sent to the browser
      • Can’t have more than 20 cookies/server
      • Cookies ONLY persist until the browser closes UNLESS you specify an expiry date:
      • set Cookie(“name”, $value, time() + 3600);
    • Sessions
      • Sessions are just like cookies, except they store the user’s data on the web server. Every request has a unique session id.
      • Sessions are more reliable than cookies.
    • Session Example
      • ?php
      • // start the session session_start(); // Get the user's input from the form $name = $_POST['name']; // Register session key with the value $_SESSION['name'] = $name; ?>
    • Destroying a Session
      • <?php // start the session session_start(); $_SESSION = array(); session_destroy();
      • if($_SESSION['name'])
      • {     print &quot;The session is still active&quot;; } 
      • else 
      • {     echo &quot;Ok, the session is no longer active! <br />&quot;;      }
      • ?>