2

Im not sure what could be causing this, But my project has been working fine in development.

But when I uploaded it to AppFog, suddenly my sessions/Auth() wont hold.

Authentication works to login. So a user can login, and will be redirected to their profile page... and from there they can update stuff...

So Auth() is obviously holding their session, but wierdly when they click anywhere else on the site, away from their profile.....suddenly their session is lost. And they have to re-login again if they want to navigate back to their profile.

Why would this happen in production but not development. The codebase is exactly the same. Only difference is im using Local/Production database settings, thats it. Other than that everything else is exactly the same.

Any idea what could be causing this?? Normally I would check php.ini and such, but on appfog, I doubt you can access any of the deep admin stuff.

Should I just switch from session based auth, to Redis/Database auth??? Anybody else come across this problem on AppFog, with Laravel, or YII?

UPDATE

Switching from default, to database session storage produced a strange error, of multiple entries per login. Which of course makes the Auth()attempt fail. I fixed this, by removing auto_increment on the id column of the sessions table. This fixed my one app....that was working before on the default settings.

The other app in question still does not work. It at least is now only making 1 entry in the session table on login attempt, but for some reason it isnt creating a login cookie to cross reference with that table.

In Chrome Console, under resources on the working app I have...

laravel_session -> 6

Which is referring to the id 6 in the session table, hence why it works.

In the non-working app however.....I have

laravel_session - > 41g1D4390Sd223s etc etc

Which as far as I can tell, isn't referring to anything....

Any insight on this???

Kylie
  • 11,421
  • 11
  • 47
  • 78
  • I'm facing the same problem in Appfog, and I use Spring. I've been researching and it seems there is a problem with HttpSession in Appfog and if you check in your browser, the `sessionId` parameter changes in every request, so it will never hold your session more than 1 request. – maqjav Oct 16 '13 at 13:06

2 Answers2

1

This could be because AppFog is a cloud based service without persistent data storage. By default, Laravel uses disk storage for it's sessions. Switch to storing your sessions in the database and they should be maintained correctly.

Dwight
  • 12,120
  • 6
  • 51
  • 64
  • While I might agree with this, why is it that my other laravel3 app runs perfectly fine on AppFog using the exact same unaltered settings? – Kylie Aug 28 '13 at 06:42
  • But.... I am now trying the database storage of sessions...and its even worse.....whereas before I would login, it would at least log me in, but the session wont hold. Now with database as my session driver, it wont even log me in at all....but the wierd thing is, everytime I try login, it is in fact making entries in the session table. But its making 4 new entries for every attempt!!??. Going over the laravel core files, Im completely stumped as to why, or even how it could possibly do that. – Kylie Aug 28 '13 at 06:44
  • Well it now appears that both my apps are broken on appfog. I tried using database sessions on the one that was working, and it didnt work, and when I reverted back to its original state, it now is broken as well. Can login, but session wont hold.....and if I use database sessions, it wont login, but makes 4-5 entries in the session table. UGH!...Im tearing my hair out here :) – Kylie Aug 28 '13 at 07:26
  • as i said earlier, try a 3rd party session library and see where the problem lies. step by step. – itachi Aug 28 '13 at 09:45
0

i had similiar problem with both laravel3 and laravel4.

The workaround (though not recommended) is,

use Session::save() manually after putting anything in the Session.

e.g.

Session::put('foo','bar');
Session::save();

As i found it, sometimes laravel fails to call Session::save() and does not throw any exceptions or errors.

itachi
  • 6,323
  • 3
  • 30
  • 40
  • I use the Auth() class, so I opened up laravel/auth.php and changed the store function to include Session::save(); after storing the token. Didnt work :( – Kylie Aug 28 '13 at 05:48
  • The other strange thing about this, is that I have another app on appfog using Laravel3, with the exact same settings, just a different database, and it functions just fine.....Im stumped – Kylie Aug 28 '13 at 05:51
  • yup.... laravel's session is faulty as i see it. Above resolved mine. if it didn't in your case, then open up the dev console, check the session id, see it exists or not. If it does exist, then goto whatever storage you are using and see if it exists there or not.... long painful debugging ahead. if it still doesn't solve your case, (and if you want to avoid modifying core files), then go for 3rd party secure session library like _phpseclib_. – itachi Aug 28 '13 at 06:28