session_start(); // start session if (isset($_SESSION['user_id'])) { // user is logged in } else { // user is not logged in }
if (isset($_COOKIE['auth_token'])) { // user is logged in } else { // user is not logged in }In this example, a cookie called "auth_token" is used to determine whether a user is logged in. If the cookie is set, the user is considered to be logged in. These examples could be part of a larger authentication system implemented with a package library like Laravel, CodeIgniter or Symfony.