Advertisement
mrengy

session_03.php

Aug 2nd, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. <?php
  2. session_start();
  3. ob_start();
  4. ?>
  5. <!DOCTYPE HTML>
  6. <html>
  7. <head>
  8. <meta charset="utf-8">
  9. <title>Session test 3</title>
  10. </head>
  11.  
  12. <body>
  13. <?php
  14. // check whether session variable is set
  15. if (isset($_SESSION['name'])) {
  16.   // if set, greet by name
  17.   echo 'Hi, ' . $_SESSION['name'] . '. See, I remembered your name!<br>';
  18.   // unset session variable
  19.   unset($_SESSION['name']);
  20.   // invalidate the session cookie
  21.   if (isset($_COOKIE[session_name()])) {
  22.     setcookie(session_name(), '', time()-86400, '/');
  23.   }
  24.   ob_end_flush();
  25.   // end session
  26.   session_destroy();
  27.   echo '<a href="session_02.php">Page 2</a>';
  28. } else {
  29.   // display if not recognized
  30.   echo "Sorry, I don't know you.<br>";
  31.   echo '<a href="session_01.php">Login</a>';
  32. }
  33. ?>
  34. </body>
  35. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement