0

Currently having an issue I'm yet to get around, it's been on and off and not consistently most of the time. PHP session files are creating themselves but in around 90% of cases, nothing writes into the session file. I'm using PHP 7 with an Nginx web server on Ubuntu.

Here are some images of the file system...

Sessions being created

Sessions being created

Inside session files

Inside session files


This is the code for the login function

// Login user
session_start();
$_SESSION['id'] = $row['id'];
$_SESSION['username'] = $row['username'];
$_SESSION['access_token'] = "verified";
// session_write_close();
header('Location: /');

session_write_close seemed to have no effect on the result of the issue. Along with that all the $row[x] variables have data with them so that's not an issue.

I've been stuck with this issue for a couple of weeks now with no solution, yet. I've gone through the below topic as well and it's pretty much the same situation.

PHP session variables not writing to files

Phil
  • 157,677
  • 23
  • 242
  • 245
FAXES
  • 94
  • 1
  • 10
  • Just to clarify - are sessions actually not working? I mean empty session files seems weird and interesting but I'm not sure why you'd be looking at them, unless the actual problem is that sessions don't work? – Don't Panic Mar 18 '20 at 23:45
  • Actually now I see you are using `header()`. This is a common and well understood problem. – Don't Panic Mar 18 '20 at 23:48
  • Does this answer your question? [PHP session lost after redirect](https://stackoverflow.com/questions/17242346/php-session-lost-after-redirect) – Don't Panic Mar 18 '20 at 23:49
  • Hmmm. Seems odd. I'll try adding an exit after headers and see if that works. But yeah, at the moment if I go to login it takes you to the login page, you fill the info and then get directed to the home page but you're not logged in as data inside the session file is not written – FAXES Mar 18 '20 at 23:58
  • @Don'tPanic Adding the `exit();` doesn't seem to do the trick, nor do the other things from that post. I've contacted the hosting company to see if it could be that. – FAXES Mar 19 '20 at 00:32
  • Did you find a solution to this issue? I think I'm having the same problem. – mmarlow Oct 26 '22 at 11:29
  • @mmarlow, turned out to be a server session issue for memory – FAXES Oct 30 '22 at 10:47

0 Answers0