In the most simple code possible
<?php
$ok = session_start();
echo var_dump($ok);
?>
starting the session fails, $ok
is false and no session cookie is created. Likewise, naming the session using session_name('xxx');
has no effect. The $_SESSION
variable also doesn't persist values if set in another script.
Other legacy scripts on the same server that use the session feature work as expected. The same script works fine when run on localhost.
The steps I did during error analysis where:
- I removed naming the session and everything else to get the script above (bare minimum example reproduces the error).
- I checked the error log my provider offers, but no entry at all was found
- I made sure that no additional whitespace is present, and all scripts immediately start with
session_start()
. - In the same script I showed
phpinfo()
to mark that:Session Support: enabled
session.auto_start: Off
session.use_cookies: 1
session.use_only_cookies: 1
(disputed, but since other scripts work...)
- I started doubting my sanity.
- I remembered running into "invisible characters" in form of byte-order-marks in text files before and figured, that maybe something like encoding might be a problem (see answer below) ...
What are additional sources for error that could cause these symptoms?