Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if( $_SESSION['auth'] != 1 ) {
- require( 'login.php' );
- }
- else {
- echo "hello";
- }
- ?>
- <?php
- $name = $_POST['name'];
- $pass = $_POST['pass'];
- if( isset($name) || isset($pass) )
- {
- if( empty($name) ) {
- die ("ERROR: Please enter username!");
- }
- if( empty($pass) ) {
- die ("ERROR: Please enter password!");
- }
- if( $name == "<some name>" && $pass == "<some password>" )
- {
- // Authentication successful - Set session
- session_start();
- $_SESSION['auth'] = 1;
- setcookie("username", $_POST['name'], time()+(84600*30));
- echo "Access granted!";
- }
- else {
- echo "ERROR: Incorrect username or password!";
- }
- }
- // If no submission, display login form
- else {
- ?>
- <html>
- <head></head>
- <body>
- <center>
- <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
- Username: <input type="text" name="name" value="<?php echo $_COOKIE['username']; ?>">
- <p />
- Password: <input type="password" name="pass">
- <p />
- <input type="submit" name="submit" value="Log In">
- </center>
- </body>
- </html>
- <?php
- }
- ?>
- header('Location: index.php');
- exit;
- session_start();
- if (!isset($_SESSION['auth']) || $_SESSION['auth'] != 1) {
- header('Location: login.php');
- exit();
- }
- echo 'Hello';
- session_start();
- if( $name == "<some name>" && $pass == "<some password>" )
- {
- // Authentication successful - Set session
- $_SESSION['auth'] = 1;
- setcookie("username", $_POST['name'], time()+(84600*30));
- header('Location: index.php');
- exit();
- }
- else {
- echo "ERROR: Incorrect username or password!";
- }
- $name = isset($_POST['name']) ? $_POST['name'] : '';
- $_SESSION['user'] = 'John';
- header('Location: index.php');
- exit;
- <?php
- session_start();
- if (empty($_SESSION['user'])) {
- $name = isset($_POST['name']) ? $_POST['name'] : '';
- $pass = isset($_POST['pass']) ? $_POST['pass'] : '';
- if ($name != '' || $pass != '')
- {
- if ($name === '')
- die("ERROR: Please enter the username!");
- if ($pass === '')
- die("ERROR: Please enter the password!");
- if ($name == "test" && $pass == "test") {
- // authentication successful, save username in session:
- $_SESSION['user'] = 'John';
- // redirect to index.php to welcome the logged in user:
- header('Location: index.php');
- exit;
- }
- else {
- die("ERROR: Incorrect username or password!");
- }
- }
- // no submitted data, display form:
- ?>
- <html>
- <head></head>
- <body>
- <center>
- <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
- Username: <input type="text" name="name" value=""><br>
- Password: <input type="password" name="pass"><br>
- <input type="submit" value="Log In">
- </form>
- </center>
- </body>
- </html>
- <?php
- }
- else {
- // info about current user is stored in session, welcome this user:
- echo "hello " . $_SESSION['user'];
- }
- ?>
- if( $name == "<some name>" && $pass == "<some password>" )
- {
- // Authentication successful - Set session
- session_start();
- $_SESSION['auth'] = 1;
- setcookie("username", $_POST['name'], time()+(84600*30));
- //echo "Access granted!";
- header("Location: index.php");
- die('');
- }
- $_SESSION['user']=$_POST['name'];
- if (isset($_SESSION['user']))
- echo "Hello, " . $_SESSION['user'];
- if($_SESSION['auth'] != 1) {
- require('login.php');
- }
- // Either way always print.
- echo "hello";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement