logging in or signing up presentation-sessions-cookies-php-5-1200979079583482-4 rishitta Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINT lite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 41 Category: Science & Tech.. License: All Rights Reserved Like it (0) Dislike it (0) Added: August 10, 2011 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Sessions and Cookies: Sessions and CookiesHow to maintain state in a stateless web: How to maintain state in a stateless webWhat is meant by state?: 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 : Methods for maintaining state Cookies Sessions Passing [hidden] variablesWhat is a cookie?: 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: Cookie Example <?php $count++; setCookie(“count”, $count); ?> Welcome! You’ve seen this site <?php print($count . ($count == 1 ? “ time!” : “ times!”)); ?>Common Pitfalls: 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 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: 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: Destroying a Session <?php // start the session session_start(); $_SESSION = array(); session_destroy(); if($_SESSION['name']) { print "The session is still active"; } else { echo "Ok, the session is no longer active! <br />"; } ?> You do not have the permission to view this presentation. In order to view it, please contact the author of the presentation.
presentation-sessions-cookies-php-5-1200979079583482-4 rishitta Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINT lite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 41 Category: Science & Tech.. License: All Rights Reserved Like it (0) Dislike it (0) Added: August 10, 2011 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Sessions and Cookies: Sessions and CookiesHow to maintain state in a stateless web: How to maintain state in a stateless webWhat is meant by state?: 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 : Methods for maintaining state Cookies Sessions Passing [hidden] variablesWhat is a cookie?: 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: Cookie Example <?php $count++; setCookie(“count”, $count); ?> Welcome! You’ve seen this site <?php print($count . ($count == 1 ? “ time!” : “ times!”)); ?>Common Pitfalls: 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 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: 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: Destroying a Session <?php // start the session session_start(); $_SESSION = array(); session_destroy(); if($_SESSION['name']) { print "The session is still active"; } else { echo "Ok, the session is no longer active! <br />"; } ?>