tags:

views:

87

answers:

2

Is it possible to modify the values inside the super global array _Session in PhP? Assume that the _Session is writing to files.

The reason I ask this is because I have two application, the front end and the back end. The backend uses some variables inside the _Session object, and the front end must be able to modify those values so that it can communicate with the backend.

+1  A: 

$_SESSION is just as modifiable as $_POST and $_GET, just know that writing to $_SESSION and then doing a header redirect does not work since the session values arent written.

Ólafur Waage
+2  A: 

If the two application are sharing a PHP session, then each can happily modify $_SESSION.

For this to happen you will need to make sure both applications are storing the sessions in the same place and either:

  • Both are on the same domain and the cookie path has not been changed e.g. using session_set_cookie_params().

or

  • You know the sessionid of the 'back end' application and in your 'front end' application call session_id('back-end SessionId here') before calling session_start(). The two applications should then have the same session. The front-end application would then lose any data it had already stored up to this point in its original session.

Either way, two applications communicating by sharing session data doesn't seem a great solution

Tom Haigh