. */ define('ROOT', rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/'); require_once ROOT . '/php/session.php'; require_once ROOT . '/php/database.php'; if ($_SERVER["REQUEST_METHOD"] == "POST") { $username = $_POST['username']; $password = $_POST['password']; $remember = isset($_POST['remember']); try { $sql = "SELECT id, username, password, verification_code FROM users WHERE username = :username"; $user = fetch_row($sql, ['username' => $username]); } catch (\PDOException $e) { echo "Error: " . $e->getMessage(); exit; } // The same message either way, so it does not say which usernames exist if (!$user || !password_verify($password, $user['password'])) { echo "Username or password is not correct!"; exit; } if ($user['verification_code'] != '0001') { set_user_id((int)$user['id']); header("Location: /signup/verify"); exit; } sign_in((int)$user['id'], $user['username'], $remember); header("Location: /"); } ?>