Support / KnowledgeBase

 
Search the KnowledgeBase Search

(gs) PHP Sessions do not work as expected

  • Applies to: (gs)

  • Difficulty: Easy

  • Time needed: 10 minutes

  • Tools needed: None

 
  • Applies to: (gs)
    • Difficulty: Easy
    • Time Needed: 10
    • Tools Required: None

Symptoms

  • Randomly being logged out of your PHP application.
  • Sessions are not saving when transitioning from HTTP to HTTPS protocols. If a PHP session needs to begin in HTTP and switch to HTTPS, there will be some issues where the session is not maintained across that transition.
  • General problems with sessions not seeming to be carried across web requests.
  • Sessions in general behave inconsistently. Your script has a dependency on writing data to the /tmp directory.
  • Although this workaround is intended for a few issues we've noticed in regards to specific cases, this will most likely fix a large majority of cases where you're having problems with sessions working properly - if you are having problems with sessions and your symptoms don't quite exactly fall into the description above, we suggest you try this workaround anyway.
  • If you are not yet using a custom php.ini file on your server, you may follow this article on the process before proceeding with the steps in this article.

Solution

This can be fixed by configuring a directive inside of a custom php.ini file to explicitly direct session files to save in a local directory on your (gs) Grid-Service instead of the default global '/tmp' folder.

This directive must be placed inside of your php.ini file on the very last line of the file:

session.save_path = /home/00000/data/tmp

Where 00000 is your actual site number. So, for s00000.gridserver.com, you would use the following:

session.save_path = /home/00000/data/tmp


After saving these changes, make sure to navigate to your 'data' directory and create a folder called 'tmp'. The next session created will start behaving properly and the problem should no longer occur.


User Comments

No visitor comments posted. Post a comment
Fields marked with an asterisk(*) are required. Comment on this article
Fill out the form below if you would like to comment on this article.
 
 
 

(code is not case-sensitive)
 
Submit
 
 

Continue