Magento 2

How to check in Magento 2.4.4 Customer is logged in or not in phtml

Easy way to check whether customer logged in or not via customer Js component.

<div data-bind="scope: 'customer'">
    <!-- ko if: customer().fullname -->
        Logged In customer
    <!-- /ko -->
    <!-- ko ifnot: customer().fullname -->
         Notlogged In customer
    <!-- /ko -->
</div>

<script type="text/x-magento-init">
{
    "*": {
        "Magento_Ui/js/core/app": {
            "components": {
                "customer": {
                    "component": "Magento_Customer/js/view/customer"
                }
            }
        }
    }
}
</script>

You can check vendor/magento/module-theme/view/frontend/templates/html/header.phtml file for example.