3

Below are functions that print $_SESSION.

public function foo() {
    print($_SESSION); 
}

public function bar() {
    print($_SESSION); 
}

public function anyOtherFunctionName() {
    print($_SESSION); 
}

We are facing a problem that all functions print $_SESSION in the local environment and $_SESSION is not empty for any function. In the production environment, only the foo() function prints $_SESSION containing information. $_SESSION in any other function is always empty.

If we change foo() function name to whatever(), $_SESSION is also empty in the production environment. And if we change the bar() function name to foo() function name on the production environment, $_SESSION which was empty, is not empty anymore.

So, on the production environment $_SESSION is always empty in any function name, except the name foo().

On the local environment, $_SESSION is never empty in any function.

Is it possible that someone can configure some PHP server configuration to always empty $_SESSION if it is not the foo() function? Any idea how we can debug that when $_SESSION is never empty in any function name in local environment?

O Connor
  • 4,236
  • 15
  • 50
  • 91
  • `$_SESSION` is superglobal, it should be visible everywhere. Did you call `session_start();` late? – Andrea Jan 04 '19 at 11:30
  • Take a look into this one, probably you'll find the answer, seems that this is a configuration issue: https://stackoverflow.com/questions/32356373/how-to-disable-sessions-in-php-with-a-specific-function – Ivan Ovcharenko Jan 04 '19 at 11:31
  • You can add this code in one of function and check if (session_status() == PHP_SESSION_NONE) { session_start(); } I think session_start() function is not call at first line of page in your code. Because some server or PHP version can only get session function only at first line without space. Please check your PHP version on both local and live server – Bhavin Thummar Jan 04 '19 at 11:31

0 Answers0