Advertisement
Riju18

no.65_session destroy[log out]

Jul 27th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.24 KB | None | 0 0
  1. ### 2file
  2. session.php
  3. ---------------
  4. ----------------
  5.  
  6. <?php
  7.   $name=$pass="";
  8.   session_start();
  9.  ?>
  10. <!DOCTYPE html>
  11. <html>
  12.   <head>
  13.     <meta charset="utf-8">
  14.     <title>session</title>
  15.     <link rel="stylesheet" href="/css/master.css">
  16.     <style media="screen">
  17.       *{margin: 0;padding: 0;}
  18.        body{background-color: gray;}
  19.       .header
  20.       {
  21.         width: 960px;
  22.         height: 50px;
  23.         background: green;
  24.         margin: 20px auto;
  25.         border: 2px solid white;
  26.         border-radius: 10px;
  27.       }
  28.       .header h2
  29.       {
  30.         color: white;
  31.         margin-left: 200px;
  32.         padding: 8px;
  33.         font-family: arial;
  34.       }
  35.       .main
  36.       {
  37.         width: 960px;
  38.         height: 450px;
  39.         background: green;
  40.         margin: 10px auto;
  41.         border: 1px solid white;
  42.         border-radius: 20px;
  43.       }
  44.       .main .code
  45.       {
  46.         margin: 10px 20px;
  47.         color: white;
  48.         font-weight: bold;
  49.         font-size: 20px;
  50.         font-family: verdana;
  51.       }
  52.       .footer
  53.       {
  54.         width: 960px;
  55.         height: 50px;
  56.         background: green;
  57.         margin: 10px auto;
  58.         border: 2px solid white;
  59.         border-radius: 10px;
  60.       }
  61.       .footer h2
  62.       {
  63.         color: white;
  64.         margin-left: 250px;
  65.         padding: 8px;
  66.         font-family: arial;
  67.       }
  68.       .second
  69.       {
  70.         margin-left: 120px;
  71.       }
  72.     </style>
  73.   </head>
  74.   <body>
  75.     <div class="header">
  76.       <h2>How session variable works:</h2>
  77.     </div>
  78.     <div class="main">
  79.       <div class="code">
  80.         <p>Basic of session:</p>
  81.         <br>
  82.         <p>put username and passord to log in  access content page:</p><br>
  83.         goto <a href="contact.php" target="_blank">content</a>  page
  84.         <br><br>
  85.         <form class="form" action="" method="post">
  86.           <table>
  87.             <tr>
  88.               <td>username:</td>
  89.               <td><input type="text" name="user" value="" autofocus></td>
  90.             </tr>
  91.             <tr>
  92.               <td>Password:</td>
  93.               <td><input type="password" name="pass" value="" autofocus></td>
  94.             </tr>
  95.             <tr>
  96.               <td></td>
  97.               <td>
  98.                 <input type="submit" name="prcoeed" value="prceed">
  99.               </td>
  100.             </tr>
  101.           </table>
  102.         </form>
  103.  
  104.         <?php
  105.           if(isset($_POST['prcoeed']))
  106.           {
  107.             $name = $_POST['user'];
  108.             $pass = $_POST['pass'];
  109.             $_SESSION['username'] = $name;
  110.             echo $_SESSION['username'];
  111.             echo "<br>";
  112.             echo "session variable is set";
  113.           }
  114.          ?>
  115.          <form class="second" action="" method="post">
  116.            <table>
  117.              <td></td>
  118.              <td><input type="submit" name="out" value="Log out"></td>
  119.            </table>
  120.          </form>
  121.          <?php
  122.             if(isset($_POST['out']))
  123.             {
  124.               session_destroy();
  125.             }
  126.           ?>
  127.       </div>
  128.     </div>
  129.     <div class="footer">
  130.       <h2>&copy; the hompage is created by <i>Riju</i></h2>
  131.     </div>
  132.   </body>
  133. </html>
  134.  
  135. contact.php
  136. --------------
  137. ----------------
  138.  
  139. <?php
  140.   session_start();
  141.  ?>
  142. <!DOCTYPE html>
  143. <html>
  144.   <head>
  145.     <meta charset="utf-8">
  146.     <title>session</title>
  147.     <link rel="stylesheet" href="/css/master.css">
  148.     <style media="screen">
  149.       *{margin: 0;padding: 0;}
  150.        body{background-color: gray;}
  151.       .header
  152.       {
  153.         width: 960px;
  154.         height: 50px;
  155.         background: green;
  156.         margin: 20px auto;
  157.         border: 2px solid white;
  158.         border-radius: 10px;
  159.       }
  160.       .header h2
  161.       {
  162.         color: white;
  163.         margin-left: 200px;
  164.         padding: 8px;
  165.         font-family: arial;
  166.       }
  167.       .main
  168.       {
  169.         width: 960px;
  170.         height: 450px;
  171.         background: green;
  172.         margin: 10px auto;
  173.         border: 1px solid white;
  174.         border-radius: 20px;
  175.       }
  176.       .main .code
  177.       {
  178.         margin: 10px 20px;
  179.         color: white;
  180.         font-weight: bold;
  181.         font-size: 20px;
  182.         font-family: verdana;
  183.       }
  184.       .footer
  185.       {
  186.         width: 960px;
  187.         height: 50px;
  188.         background: green;
  189.         margin: 10px auto;
  190.         border: 2px solid white;
  191.         border-radius: 10px;
  192.       }
  193.       .footer h2
  194.       {
  195.         color: white;
  196.         margin-left: 250px;
  197.         padding: 8px;
  198.         font-family: arial;
  199.       }
  200.     </style>
  201.   </head>
  202.   <body>
  203.     <div class="header">
  204.       <h2>How session variable works:</h2>
  205.     </div>
  206.     <div class="main">
  207.       <div class="code">
  208.         <p>Basic of session:</p>
  209.         <br>
  210.         <p>contact page:</p><br>
  211.         goto <a href="session.php" target="_blank">session</a>  page
  212.         <br><br>
  213.         <?php
  214.             if(!isset($_SESSION['username']))
  215.             {
  216.               $_SESSION['username'] = "";
  217.             }
  218.             else {
  219.                echo $_SESSION['username']."(session variable which is set in session page)";
  220.             }
  221.          ?>
  222.       </div>
  223.     </div>
  224.     <div class="footer">
  225.       <h2>&copy; the hompage is created by <i>Riju</i></h2>
  226.     </div>
  227.   </body>
  228. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement