In my index.php file I call session_start() and set a couple of session variables. In a second PHP file I would like to access these session variables.
Thing is, this PHP file is purely a backend script and is POSTed to when a JavaScript function is triggered. When the POST call attempts to cause the script in the second PHP file to be executed the error log is reporting that:
_SESSIONis an undefined variable.
I’ve tried calling start_session() and session_regenerate_id() at the top of the second PHP file but the issue has persisted.
I’m assuming what is going on is that because it’s in a POST this PHP file is in its own session as I am still able to do this $_COOKIE[ini_get('session.name')].
The information that I am trying to pass to the second PHP file isn’t anything that needs to be secured but it would be nice to know in the future how to do this: call a PHP file via a POST and still have my session variables.
There’s nothing special whatsoever about POST requests and sessions.
You just need to call
session_startat the top of everyfilerequest you want to use sessions in, that’s it.Try again with that in mind, it ought to work.