Checking if a cookie is set Upon visiting my website, I check if a cookie is set into the user's browser and proceed to logging him into his account. Currently, I do the cookie check in my init.php file and I am asking where I should put it instead because I don't feel like this is the ideal place to be.

Here is my init.php file:

&lt;?php
session_start();
error_reporting(E_ALL);

require_once "config.php";
require_once "functions/functions.php";
require_once __DIR__ . '/../vendor/autoload.php';

use \App\Core as App;
use \App\Models\Auth\Login as Login;
use \App\Core\Database as Database;

$app = new App\App();

/**
 * Checks if login cookie exists and log in the user
 */
if(isset($_COOKIE['cookie_hash']) &amp;&amp; isset($_SESSION['cookie_hash']))
{
    $login = new Login(Database::getInstance());
    $login-&gt;cookieLogin($_COOKIE['cookie_hash'], $_SESSION['cookie_hash']);
}

App\FlashMessage::clear();


And yeah this App\FlashMessage::clear(); seems out of place too. Its only purpose is to unset the flash_message session. If you have a suggestion where to move it, I'd appreciate it too. If I get rid of the cookie check, I can then remove these 2 lines: 

use \App\Models\Auth\Login as Login;
use \App\Core\Database as Database;


and my code will be much cleaner.

This is how my file structure looks like:



I was thinking about moving it into Public/index.php which only requires the init.php file but I am not sure.
yes its possible you need in index file include the ini file 

require_once "../app/function/init.php";


and also need .htaccess something look like that 

Options -MultiViews
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On

RewriteBase MVC/Source Files/public

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [L,QSA] 

&lt;/IfModule&gt;


you can also put php ini file script in index.php file inside public directory 

&lt;?php
session_start();
error_reporting(E_ALL);

require_once "../app/functions/onfig.php";
require_once "../app/functions/functions.php";
require_once __DIR__ . '/../vendor/autoload.php';

use \App\Core as App;
use \App\Models\Auth\Login as Login;
use \App\Core\Database as Database;

$app = new App\App();

/**
 * Checks if login cookie exists and log in the user
 */
if(isset($_COOKIE['cookie_hash']) &amp;&amp; isset($_SESSION['cookie_hash']))
{
    $login = new Login(Database::getInstance());
    $login-&gt;cookieLogin($_COOKIE['cookie_hash'], $_SESSION['cookie_hash']);
}

App\FlashMessage::clear();


you can install session in your App.php file so session start automatically in every file no need to write