<?php
require_once('fam.php');

$login = trim($_REQUEST['login']);
$q = dbq('select id, name from users where login = :login',
	['login'=>$login]);
$row = $q->fetch();

# Row is false value if there are no more rows
if(!$row):
?>
        <!DOCTYPE html>
        <html lang="en">
        <head>
          <title>Fam! Login</title>
          <meta charset="utf-8">
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <link rel="icon" type="image/png" sizes="16x16" href="/hearts.png">
          <link rel="stylesheet" href="/styles.css">
        </head>
        <body>
        <h1>Bad Login</h1>
        <p>Sorry! That login code was wrong somehow. You may need a new one.</p>
        <p><a href="not-logged-in.html">Go back and try again</a></p>
        </body>
        </html>
<?php
        exit;
endif;

# Store the login for lookup on every page. This is the way.
$ten_years = 315360000; # in seconds
setcookie(
        'login',              # Cookie name
        $login,               # Value
        time() + $ten_years,  # Expires
        '/'                   # Path where cookie valid
);
header('Location: /');
