Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset($_COOKIE['PHPSESSID'])) {
- session_start();
- }
- if (isset($_POST['user'])) {
- if ($_POST['user'] != '') {
- $user = $_POST['user'];
- }
- if(isset($_POST['password'])) {
- if ($_POST['user'] != '') {
- $password = $_POST['password'];
- }
- }
- if (isset($user) && isset($password)) {
- session_regenerate_id(true);
- $_SESSION['user'] = $user;
- $_SESSION['password'] = $password;
- }
- }
- ?>
- <html>
- <head>
- <title>PHP Sessions</title>
- <style type="text/css">
- body {
- text-align: center;
- }
- </style>
- </head>
- <body>
- <?php
- //CHECK FOR SESSION
- if(!isset($_SESSION['user']))
- {
- ?>
- <h1>Login Page</h1>
- <h2>Today is<?php echo date("l \\t\h\e jS"); ?></h2>
- <h3>Session ID is: <?php echo session_id(); ?></h3>
- <form method="POST" action="php">
- <label>Username:</label> <input type="text" id="user" name="user" /><br /><br />
- <label>Password:</label> <input type="password" id="password" name="password" /><br /><br />
- <input type="submit" name="login" id="login" value="Login" />
- </form>
- <?php
- }
- else
- {
- echo "<h1>You are now logged in!</h1>";
- echo "<h3>The new Session ID is: ";
- echo session_id();
- echo "</h3>";
- var_dump($_COOKIE);
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment