Presentation Sessions & Cookies PHP 5

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    2 Favorites

    Presentation Sessions & Cookies PHP 5 - Presentation Transcript

    1. Sessions and Cookies
    2. How to maintain state in a stateless web
    3. 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.
    4. Methods for maintaining state
      • Cookies
      • Sessions
      • Passing [hidden] variables
    5. 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.
    6. Cookie Example
      • <?php
      • $count++;
      • setCookie(“count”, $count);
      • ?>
      • Welcome! You’ve seen this site
      • <?php print($count . ($count == 1 ? “ time!” : “ times!”)); ?>
    7. 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);
    8. 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.
    9. 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; ?>
    10. 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;;      }
      • ?>

    + sanjaysanjay, 2 years ago

    custom

    2375 views, 2 favs, 0 embeds more stats

    This is a Presentation for PHP5 for Sessions and Co more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 2375
      • 2375 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 46
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories