PHP sessions empty

I have deployed a container from the official docker hub php:7.2-apache, kept the same source code as an existing web site which has a simple user login using PHP’s session variable.

However, the $_SESSION always seems to be empty. The login page posts to itself, and I have been debugging what is / should be there.

Known or expected behaviour?

How can I change the container or the PHP config to work as expected?

Did you find a solution to this problem? I set up a php-apache container by myself and experience the same problem.
I found out that this must be related to the creation and deletion of php’s session files. I tracked the folder specified in session.save_path and found out that a session file is created but immediately gets deleted (within 1 second).
However, I tried to adjust session.gc parameters and a lot of other stuff and didn’t find a solution to this.

In my case, it was because the session start / check needed to be right at the top of the PHP file. In my transition to Docker, the PHP version changed.

Basically, I moved the following code right to the top of each page, before any HTML or anything, that used the session variable for a user login:

<?php
session_start();
include 'functions.php';


if(empty($_SESSION['user'])) 
{
    header("Location: login.php");
    die("Redirecting to login.php"); 
}
?>

I went through every page that needed an active login.

Hello there,
I’m trying to run a PHP instance on Apache. I am unable to use it to connect it to a MySQL DB. I’ve managed to add PBO mysql using docker exe on the command line but its not enough to use PHPBB on MySQL because, the installer is only giving me SQLite as an option. What do I do, LiteBlue please help!.

I’ve managed to add PBO mysql using docker exe on the command line but its not enough to use PHPBB on MySQL because, the installer is only giving me SQLite as an option. What do I do, Liteblue Login please help!