You can check user is logged in or not on the website through a user session in Magento 2. This piece of code is working in any file.
Category: Magento 2
Magento 2 is the latest upgrade of Magento, which was originally developed by Varien Inc. Started officially in 2007, which to be more certain, August 31 is the date of first public beta version release.
On November 17, 2015, Magento 2 was officially released. Inherited lots of success factors of Magento, Magento 2 also present modern technologies and structure, as well as modified directory structure but more simplified customization. Now Magento 2 and Magento 1 are existing simultaneously.
Magento 2: Commands
Magento 2 has one command-line interface that performs both installation and configuration tasks. Console component is one of the new features in Magento 2. Find various command here.