Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>PHP - Login</title>
- </head>
- <body>
- <?php
- function isUserLogged() {
- if (isset($_SESSION['logged']) && $_SESSION['logged'] === 1)
- return true;
- return false;
- }
- function getUser() {
- return [
- 'login' => 'admin',
- 'password' => '123',
- ];
- }
- function login($login, $password) {
- $user = getUser();
- if ($login === $user['login'] && $password === $user['password']) {
- $_SESSION['login'] = $user['login'];
- $_SESSION['password'] = $user['password'];
- $_SESSION['logged'] = 1;
- return true;
- } else {
- return false;
- }
- }
- session_start();
- if (isset($_POST['submit'])) {
- $data = $_POST;
- // print_r($data); // DEBUG
- if (!login($data['login'], $data['password'])) {
- echo "Login e/ou senha incorreta!";
- }
- }
- ?>
- <?php if (isUserLogged()) : ?>
- <h1>User Panel</h1>
- <p>
- Login: <strong><?= getUser()['login'] ?></strong>
- <br> Password: <strong><?= getUser()['password'] ?></strong>
- </p>
- <?php else : ?>
- <form action="#" method="post">
- <label for="login">Login:</label>
- <input type="text" name="login" id="login" required>
- <br>
- <label for="password">Password:</label>
- <input type="password" name="password" id="password" required>
- <br>
- <button type="submit" name="submit">Login</button>
- </form>
- <?php endif; ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement