0

I have a problem in my application using SESSION array. It has been working for a couple of weeks but then suddenly stopped working (without any noticable change in code or settings). I shortened the code to this:

<?php
   session_start();
   var_dump($_SESSION);
   $_SESSION['meh'] = 'MEH';
?>

It shows an error: 'A session has alredy been started...'. This is now my whole code in index.php, which is the only file in server's directory. After the second (third...) run the $_SESSION is still empty. Working with PHP 7.0, testing on Firefox and Opera (Cookies allowed). On local server is everything fine. Any ideas how to fix it? Somewhere in config/cache or whatever? Thanks

TSGR
  • 35
  • 2
  • you can't var dump before you assign a session array. – Funk Forty Niner Feb 21 '18 at 16:52
  • you're including/requring files elsewhere that we don't know about? – Funk Forty Niner Feb 21 '18 at 16:52
  • Of course I can dump it, because it is a $_SESSION. For the first time it will dump empty array, but for the second time, it should dump an array with index 'meh', because it's a session. Thats the problem, because during the second time I run it, still - nothing is in the $_SESSION array. This is my only code. Only code in one file, nothing else. – TSGR Feb 21 '18 at 17:03
  • Check your runtime configs for auto-starting the session. Someone may have turned it on on your server without you realizing it ... http://php.net/manual/en/session.configuration.php – IncredibleHat Feb 21 '18 at 17:06
  • Good point, it has somehow changed to value "On", so I disabled it. Fixed the issue with 'A session has already been started', but $_SESSION array still terminates after every single run of the script. :/ – TSGR Feb 21 '18 at 17:14

1 Answers1

0

you may have another session_start() in your code

or

try this

from the old answer

<?php
    if(!isset($_SESSION)) 
    { 
        session_start(); 
    } 
?>
jasinth premkumar
  • 1,430
  • 1
  • 12
  • 22
  • Nope, that's not it. Sure, I can overcome the issue with session already started (I've checked that thread before), but that's not why my $_SESSION does not work as session array. Nevertheless - thanks for your time. – TSGR Feb 21 '18 at 17:11
  • make sure you have it in top of the page – jasinth premkumar Feb 21 '18 at 17:14
  • hey checkout this answer http://stackoverflow.com/questions/10648984/php-sessions-that-have-already-been-started/10649030#10649030 – jasinth premkumar Feb 21 '18 at 17:16
  • The code above is my only code, there is nothing more. So yes, I think it is in the very top of the page. Disabling session.auto_start finally prevents the issue with 'A session has already been started', but not the whole disfunction of $_SESSION array. After the script ends, $_SESSION is empty. The first issue is solved for now. The main issue not yet. – TSGR Feb 21 '18 at 17:23
  • What do you mean by that? Checking if all indexes and array names are correctly written? – TSGR Feb 21 '18 at 17:32
  • Well, that can't be my problem, because I have only one index (which I actually don't use, because I dump the whole $_SESSION array) and one $_SESSION array. The code in my question is complete, there is nothing else. And now I've just found that my COOKIES (on this server) are not working anymore too. I can use previously set COOKIES but not new COOKIES. – TSGR Feb 21 '18 at 18:14