Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

PHP Cookies, Sessions and Authentication

14,845 views

Published on

Do you know the difference between the PHP config directives session.gc_maxlifetime and session.cookie_lifetime? Have you wrestled with implementing a “Remember Me” button on your login page? Learn how popular sites, such as Twitter and Facebook, keep you logged in (apparently) forever and the security risks of such methods.

http://github.com/hellogerard/tek11

Published in: Technology, Self Improvement
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

PHP Cookies, Sessions and Authentication

  1. 1. (PHP) Sessions, Cookies, & Authentication Gerard Sychay #tek11 05/26/2011
  2. 2. Gerard Sychay. Zipscenemobile.com Cincy Coworks Introduction 0.
  3. 3. 0. Introduction This is Henry
  4. 4. Introduction 0. baby
  5. 5. Introduction 0. <ul><li>Sessions </li></ul><ul><li>Authentication </li></ul><ul><li>Keep Me Logged In </li></ul><ul><li>Security </li></ul>
  6. 6. Sessions 1. 1. initial request 2. create new session ID 3. create session file named with ID 4. store ID in ‘ PHPSESSID’ cookie
  7. 7. Sessions 1. 2. find file with name matching session ID 3. read session data from session file <ul><li>read session ID from </li></ul><ul><li>PHPSESSID cookie </li></ul>4. respond using session data
  8. 8. Sessions 1.
  9. 9. Authentication 2. Sessions… what are they good for?
  10. 10. // set a flag $_SESSION[‘authenticated’] = true; $_SESSION[‘loggedIn’] = true; // save something useful $_SESSION[‘userId’] = 123; $_SESSION[‘userName’] = ‘jsmith’; Authentication 2.
  11. 11. Authentication 2.
  12. 12. Authentication 2. “ You know that thing that they have?”
  13. 13. Specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means “until the browser is closed.” Defaults to 0. Authentication 2. session.cookie_lifetime
  14. 14. Specifies the number of seconds after which data will be seen as ‘garbage’ and potentially cleaned up. Garbage collection may occur during session start. Defaults to 1440 seconds. Authentication 2. session.gc_maxlifetime
  15. 15. Authentication 2. // 24h session.cookie_lifetime = 86400; // 24h session.gc_maxlifetime = 86400;
  16. 16. Authentication 2.
  17. 17. Authentication 2. session.cookie_lifetime Absolute expiration time session.gc_maxlifetime Maximum idle time
  18. 18. Authentication 2. session.cookie_lifetime = 0; // default session.gc_maxlifetime = 1440; // default Example Henry: Never closes his browser Requests pages every 20 minutes or so. Stays logged in!
  19. 19. Authentication 2. session.cookie_lifetime = 0; // default session.gc_maxlifetime = 1440; // default Example Henry: Leaves his browser open Takes a 30 min. snack break Session garbage collected – logged out!
  20. 20. Authentication 2. session.cookie_lifetime = 3600; // 1 hr session.gc_maxlifetime = 1440; // default Example Henry: Leaves his browser open Takes a 30 min. snack break Session garbage collected – logged out!
  21. 21. Authentication 2. session.cookie_lifetime = 3600; // 1 hr session.gc_maxlifetime = 3600; // 1 hr Example Henry: Leaves his browser open Takes a 45 min. snack break Works for 30 mins. Session cookie expires – logged out!
  22. 22. Oh yeah, what was I trying to do? Authentication 2.
  23. 23. Authentication 2.
  24. 24. Keep Me Logged In 3. do? What would
  25. 25. Keep Me Logged In 3. 1. initial login 4. store auth token in ‘my_auth’ cookie 3. store user’s unique auth token in DB 2. create new auth token for user
  26. 26. Keep Me Logged In 3. 1. read auth token from ‘my_auth’cookie 2. lookup auth token in DB 4. Store new session ID and auth token in cookies 3. if valid token, log user in
  27. 27. Keep Me Logged In 3.
  28. 28. What about security? Security 4.
  29. 29. Security 4.
  30. 30. Security 4. Firesheep
  31. 31. Security 4.
  32. 32. I CAN HAZ SSL? Security 4.
  33. 33. Re-authenticate! Security 4.
  34. 34. 4. Security
  35. 35. @hellogerard http://straylightrun.net http://github.com/hellogerard/tek11 © 2011. Some rights reserved. Thanks! 5. Enjoy the wi-fi!

×