Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### 2file
- session.php
- ---------------
- ----------------
- <?php
- $name=$pass="";
- session_start();
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>session</title>
- <link rel="stylesheet" href="/css/master.css">
- <style media="screen">
- *{margin: 0;padding: 0;}
- body{background-color: gray;}
- .header
- {
- width: 960px;
- height: 50px;
- background: green;
- margin: 20px auto;
- border: 2px solid white;
- border-radius: 10px;
- }
- .header h2
- {
- color: white;
- margin-left: 200px;
- padding: 8px;
- font-family: arial;
- }
- .main
- {
- width: 960px;
- height: 450px;
- background: green;
- margin: 10px auto;
- border: 1px solid white;
- border-radius: 20px;
- }
- .main .code
- {
- margin: 10px 20px;
- color: white;
- font-weight: bold;
- font-size: 20px;
- font-family: verdana;
- }
- .footer
- {
- width: 960px;
- height: 50px;
- background: green;
- margin: 10px auto;
- border: 2px solid white;
- border-radius: 10px;
- }
- .footer h2
- {
- color: white;
- margin-left: 250px;
- padding: 8px;
- font-family: arial;
- }
- .second
- {
- margin-left: 120px;
- }
- </style>
- </head>
- <body>
- <div class="header">
- <h2>How session variable works:</h2>
- </div>
- <div class="main">
- <div class="code">
- <p>Basic of session:</p>
- <br>
- <p>put username and passord to log in access content page:</p><br>
- goto <a href="contact.php" target="_blank">content</a> page
- <br><br>
- <form class="form" action="" method="post">
- <table>
- <tr>
- <td>username:</td>
- <td><input type="text" name="user" value="" autofocus></td>
- </tr>
- <tr>
- <td>Password:</td>
- <td><input type="password" name="pass" value="" autofocus></td>
- </tr>
- <tr>
- <td></td>
- <td>
- <input type="submit" name="prcoeed" value="prceed">
- </td>
- </tr>
- </table>
- </form>
- <?php
- if(isset($_POST['prcoeed']))
- {
- $name = $_POST['user'];
- $pass = $_POST['pass'];
- $_SESSION['username'] = $name;
- echo $_SESSION['username'];
- echo "<br>";
- echo "session variable is set";
- }
- ?>
- <form class="second" action="" method="post">
- <table>
- <td></td>
- <td><input type="submit" name="out" value="Log out"></td>
- </table>
- </form>
- <?php
- if(isset($_POST['out']))
- {
- session_destroy();
- }
- ?>
- </div>
- </div>
- <div class="footer">
- <h2>© the hompage is created by <i>Riju</i></h2>
- </div>
- </body>
- </html>
- contact.php
- --------------
- ----------------
- <?php
- session_start();
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>session</title>
- <link rel="stylesheet" href="/css/master.css">
- <style media="screen">
- *{margin: 0;padding: 0;}
- body{background-color: gray;}
- .header
- {
- width: 960px;
- height: 50px;
- background: green;
- margin: 20px auto;
- border: 2px solid white;
- border-radius: 10px;
- }
- .header h2
- {
- color: white;
- margin-left: 200px;
- padding: 8px;
- font-family: arial;
- }
- .main
- {
- width: 960px;
- height: 450px;
- background: green;
- margin: 10px auto;
- border: 1px solid white;
- border-radius: 20px;
- }
- .main .code
- {
- margin: 10px 20px;
- color: white;
- font-weight: bold;
- font-size: 20px;
- font-family: verdana;
- }
- .footer
- {
- width: 960px;
- height: 50px;
- background: green;
- margin: 10px auto;
- border: 2px solid white;
- border-radius: 10px;
- }
- .footer h2
- {
- color: white;
- margin-left: 250px;
- padding: 8px;
- font-family: arial;
- }
- </style>
- </head>
- <body>
- <div class="header">
- <h2>How session variable works:</h2>
- </div>
- <div class="main">
- <div class="code">
- <p>Basic of session:</p>
- <br>
- <p>contact page:</p><br>
- goto <a href="session.php" target="_blank">session</a> page
- <br><br>
- <?php
- if(!isset($_SESSION['username']))
- {
- $_SESSION['username'] = "";
- }
- else {
- echo $_SESSION['username']."(session variable which is set in session page)";
- }
- ?>
- </div>
- </div>
- <div class="footer">
- <h2>© the hompage is created by <i>Riju</i></h2>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement