Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### if a session variable is set once it can be accessible in all page. suppose in "the main" page we logged in with username and password. our username we can in all page along with "main" page until we log out.
- #### here 2file is created. 1)session.php 2)contact.php
- session.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>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="" 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";
- }
- ?>
- </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
- 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