Login
connect_errno) {
echo "
MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}
"; exit(); } //find username in db $sql = "SELECT * from users WHERE username LIKE '{$username}' LIMIT 1"; $result = $mysqli->query($sql); if ($result->num_rows != 1) { echo "Error: Invalid username/password combination
"; } else { // Authenticated, set session variables $user = $result->fetch_array(); //match input password with db password if (password_verify($password, $user['password'])){ $_SESSION['user_id'] = $user['id']; $_SESSION['username'] = $user['username']; // update status to online $timestamp = time(); $sql = "UPDATE users SET status={$timestamp} WHERE id={$_SESSION['user_id']}"; $result = $mysqli->query($sql); redirect_to("logged.php?id={$_SESSION['user_id']}"); } } } //message if(isset($_GET['msg'])) { echo "".$_GET['msg']."
"; } ?>