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:
_SESSION
is 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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…