Docker Community Forums

Share and learn in the Docker community.

PHP sessions empty

(Danburt) #1

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?

(Clupeidae) #2

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.

(Danburt) #3

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:

include 'functions.php';

    header("Location: login.php");
    die("Redirecting to login.php"); 

I went through every page that needed an active login.

(Lucinda956) #4

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!.