Sign in

'; if ($_SERVER['REQUEST_METHOD'] != 'POST') { echo '




'; } else { $errors = array(); if (!isset($_POST['user_name'])) { $errors[] = 'Please provide a username.'; } if (!isset($_POST['user_pass'])) { $errors[] = 'Please provide a password.'; } if (!empty($errors)) { echo 'Please check the following problems: '; } else { $sql = "SELECT user_id, user_name FROM users WHERE user_name = '" . mysqli_real_escape_string($dbc, $_POST['user_name']) . "' AND user_pass = '" . sha1($_POST['user_pass']) ."'"; $result = mysqli_query($dbc, $sql); if (!$result) { echo 'An error occurred while signing in.'; echo mysqli_error($dbc); } else { if (mysqli_num_rows($result) == 0) { echo 'There is no user with that username/password combination! Please try again'; } else { $_SESSION['signed_in'] = true; while ($row = mysqli_fetch_assoc($result)) { $_SESSION['user_id'] = $row['user_id']; $_SESSION['user_name'] = $row['user_name']; } echo 'You are now signed in as ' . $_SESSION['user_name']; } } } } echo ''; include_once 'footer.php';