I have already seen this identical opposite question and its OP code sample seems perfectly fine to me. I've also read (including PHP docs) that session can be checked with session_status() on PHP >= 5.4 and it should be fine to do so before calling session_start() to determine if it already exists.
Now, I'm using PHP 5.4.16 on a CentOS 7.10 machine and the session_status() always returns 1 (PHP_SESSION_NONE) for me, only when I reload the page with this example:
<?php
$status = session_status();
session_start();
echo "The session status is : $status";
I expect it returns PHP_SESSION_ACTIVE (2) when I reload page (and I'm not forcing-reload with cache clear). I'm using latest Chrome version, and the page is embedded inside a virtual host with HTTPS over port 8443.
I've checked the PHP version with both php --version and via phpinfo() script to discard any version conflict just in case, and they're same. Additionally, when I visit the session script page, the server creates empty files at /var/lib/php/session directory. I didn't change default PHP settings for session or anything.
To make it clear: the session_status() works fine if checked afterwards on same script execution (The session status is : 2), but naturally I'm not interested in that since I want to check if session exist in first place.
What could be wrong?