Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function before_output () {
- $html = ob_get_contents();
- return $html;
- }
- ob_start('before_output');
- if (session_id() == '') session_start();
- ?>
- <!DOCTYPE html>
- <html lang="es" dir="ltr">
- <head>
- <meta charset="UTF-8" />
- <title>Location</title>
- <style type="text/css" media="screen">
- * {margin:0;padding:0;}
- body {font-family:"Segoe UI";}
- p, h1, pre, ul {margin-bottom:15px;}
- .wrapper {width:960px;margin:0 auto;}
- input, button {padding:5px;}
- .error {background-color:#eb0000;list-style:none;padding: 15px;}
- .error li {color:#fff;}
- .success {background-color:#59b804; color: #fff;padding: 10px;}
- </style>
- </head>
- <body>
- <div class="wrapper">
- <h1>Login Form</h1>
- <?php if (isset($_SESSION['errors'])): ?>
- <ul class="error">
- <?php foreach ($_SESSION['errors'] as $error): ?>
- <li><?php echo $error; ?></li>
- <?php endforeach; ?>
- </ul>
- <?php unset($_SESSION['errors']); ?>
- <?php endif; ?>
- <?php if (isset($_SESSION['user-logged']) && $_SESSION['user-logged'] === true): ?>
- <p class="success">You are logged in now.</p>
- <?php else: ?>
- <form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" autocomplete="off">
- <p><input type="text" name="Login[username]" value="" /></p>
- <p><input type="password" name="Login[password]" value="" /></p>
- <button name="Login[submit]" type="submit" value="true">Log In</button>
- </form>
- <?php endif; ?>
- <?php
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && array_key_exists('Login', $_POST)) {
- $username = (isset($_POST['Login']['username']))
- ? htmlspecialchars(trim($_POST['Login']['username']), ENT_QUOTES, 'UTF-8')
- : '';
- $password = (isset($_POST['Login']['password']))
- ? htmlspecialchars(trim($_POST['Login']['password']), ENT_QUOTES, 'UTF-8')
- : '';
- if ($username !== 'admin') {
- $_SESSION['errors'][] = 'Nombre de usuario, no existe.';
- }
- if ($password !== 'secret') {
- $_SESSION['errors'][] = 'Contraseña incorrecta, vuelva a intentarlo';
- }
- if ($username === 'admin' && $password === 'secret') {
- $_SESSION['user-logged'] = true;
- }
- header("Location: {$_SERVER['SCRIPT_NAME']}");
- }
- ?>
- </div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment