Problem with Cakephp environment Auth / Session not working




i have a problem with my Cakephp Environment. I use Cakephp 3.5 with PHP 7.1.
I checked out the cakephp with composer as mentioned in the book. Then i started developing my Application everything worked fine.
Then i wanted to add User Authentication, and then the problems started :slight_smile:

I tried the default way for user Auth with the standard Auth Component. There it happened, that the login process didnt worked. $this->Auth->identifiy() in the controller login Action was true and in runtime i could access the user object.
But after the redirect the user object was empty again (i run Auth->setUser() too ofc).

Then i tried to fix this issue, i tried several code snippets from Stackoverflow etc, checked Server Environment, changed my dev system from local Ubuntu to my Debian test system. But nothing helped. The Auth User was only available at the time the login happens, after a redirect / reload every Auth Session was empty.

I only need simple user Auth, so I tried to implement this little thing with the normal Session Component (this->request->getSession()->write/read; etc). But the same errors happened, after a redirect / reload every single session variable is null / not there. Then i tried to change my Session storage / Handler from php, to cake, to database) but it doesnt help. I even tried to store my Session vars in the _SESSION variable, but it doesnt help too.

In other non cakephp applications on the server the session thing works just fine.

I run the app with Apache 2.2 without mod_rewrite.

Do you guys have an idea why my Session Environment doesnt work in CakePHP?
I burned several hours in this little problem and this is my last hope too fix this error.

In this case it didnt make sense to post my application code here, cause I tried so much different ways to store the session. At this moment i only have an empty UsersController :smiley:.

I think the whole problem is a specific environment thing with my CakePHP installation. Maybe i can set some configuration vars to fix this.


If I understand you correctly, then you do not save the authorization status when switching to any other page, which may mean that you did not use:

$this->Auth->setUser($admin); // $admin