Why doesn't $_SESSION work?

I have MVC project;
There is start_session() in my config

<?php

**session_start();**

$_SERVER['DOCUMENT_ROOT'] = "/storage/ssd5/780/5704780/public_html";
define("ROOT", $_SERVER['DOCUMENT_ROOT']);
define("CONTROLLER_PATH", ROOT. "/controllers/");
define("MODEL_PATH", ROOT. "/models/");
define("VIEW_PATH", ROOT. "/views/");
define("UPLOAD_DIR", ROOT. "/uploads/");

require_once("db.php");
require_once("route.php");
require_once MODEL_PATH. 'Model.php';
require_once CONTROLLER_PATH. 'Controller.php';
require_once VIEW_PATH. 'View.php';

Routing::buildRoute();

Return array(0) { } when I write var_dump($_SESSION); in CabinetController.php

    <?php

    class CabinetController extends Controller {

        private $pageTpl = "/views/cabinet.tpl.php";


        public function __construct() {
            $this->model = new CabinetModel();
            $this->view = new View();
        }

        public function index() {

            if(!$_SESSION['user']) {
                header("Location: /");
            }
            
              var_dump($_SESSION);
        
            $this->pageData['title'] = "MyCabinet";

            $ordersCount = $this->model->getOrdersCount();
            $this->pageData['ordersCount'] = $ordersCount;

            $tasksCount = $this->model->getTasksCount();
            $this->pageData['tasksCount'] = $tasksCount;

            $usersCount = $this->model->getUsersCount();
            $this->pageData['usersCount'] = $usersCount;

            $orders = $this->model->getOrders();
            $this->pageData['orders'] = $orders;

            $this->view->render($this->pageTpl, $this->pageData);
        }

        public function logout() {
            session_destroy();
            header("Location: /");
        }


    }

Why are there * before and after it?

It is a strong text ==> strong text

Website address please :slight_smile:

https://paul-74128-14.000webhostapp.com/

Try echoing some sessions

1 Like

array(0) { } everywhere

Hi @coldunox!

Sessions were not working because you were missing the /tmp folder (the default storage for session/uploaded files) from your account root path. I have added it and modified your .htaccess (check it for reference).

Please retry and confirm if the issue has been solved.

3 Likes

Thaks a lot, teodor =)