1 <?php
2 require_once('fam.php');
3
4 $login = trim($_REQUEST['login']);
5 $q = dbq('select id, name from users where login = :login',
6 ['login'=>$login]);
7 $row = $q->fetch();
8
9 # Row is false value if there are no more rows
10 if(!$row):
11 ?>
12 <!DOCTYPE html>
13 <html lang="en">
14 <head>
15 <title>Fam! Login</title>
16 <meta charset="utf-8">
17 <meta name="viewport" content="width=device-width, initial-scale=1">
18 <link rel="icon" type="image/png" sizes="16x16" href="/hearts.png">
19 <link rel="stylesheet" href="/styles.css">
20 </head>
21 <body>
22 <h1>Bad Login</h1>
23 <p>Sorry! That login code was wrong somehow. You may need a new one.</p>
24 <p><a href="not-logged-in.html">Go back and try again</a></p>
25 </body>
26 </html>
27 <?php
28 exit;
29 endif;
30
31 # Store the login for lookup on every page. This is the way.
32 $ten_years = 315360000; # in seconds
33 setcookie(
34 'login', # Cookie name
35 $login, # Value
36 time() + $ten_years, # Expires
37 '/' # Path where cookie valid
38 );
39 header('Location: /');