5 Replies Latest reply on Jun 3, 2010 3:37 PM by ninjaz1000

    Reuse current session when opening new TitleWindow

    ninjaz1000

      Environment: Linux, Apache, MySQL, PHP

       

      I'm using sessionization as provided by PHP to track user sessions. My Flex application makes resource calls from the browser to the server hosted php resources. Within my main application, the session based resource calls work fine. Unfortunately, it starts a new session when using a popup window. Specifically,  PopupManager.addPopUp() function to open a new Flex TitleWindow().

       

      > > > PopUpManager.addPopUp( loc, this, false );

       

      Apache also shows that a new session was started. How do I open a new TitleWindow that uses the same client session as the containing Flex instance?

        • 1. Re: Reuse current session when opening new TitleWindow
          Gregor.Kiddie Level 2

          Are you letting the channels you used to communicate the first time get garbage collected? Or are constructing a completely different set of channels to use?

           

          If you use the same channelset, you use the same session.

          1 person found this helpful
          • 2. Re: Reuse current session when opening new TitleWindow
            ninjaz1000 Level 1

            The TitleWindow uses custom objects that create new instances of the URLLoader & URLRequest classes, if that answers your question. Is it possible to set the channel set?

            • 3. Re: Reuse current session when opening new TitleWindow
              Gregor.Kiddie Level 2

              URLLoader doesn't use the same techniques as the Service based (like the HTTPService).

               

              At the root of it, it comes down to the session information being embedded in the headers of the HTTP request. There are a lot of header that a disallowed (check the docs) so you might not be able to add the correct headers...

               

              You might be able to get away with storing the requestHeaders from the first call you make, and adding them to the later calls.

              1 person found this helpful
              • 4. Re: Reuse current session when opening new TitleWindow
                ninjaz1000 Level 1

                Update.

                 

                I was programming from my girlfriend's machine where she doesn't have Firefox, and the sessionization is working. A new TitleWindow does not create a new session in IE while Firefox does. Perhaps it has something to do with how I configured my browser. I'm thinking the best approach is to save a variable on the client that I can save and modify consistently. If anyone knows of a better way, let me know.

                 

                Thanks.

                • 5. Re: Reuse current session when opening new TitleWindow
                  ninjaz1000 Level 1

                  Problem - Solved

                   

                  New TitleWindow was not the issue. The issue was with the fileReference.upload(request) embedded within the TitleWindow.

                   

                  Solution:

                  1. When initializing a phpsession, capture the PHPSessionID in a flex static variable:

                            PHP Function session_id()

                   

                  2. When calling  fileReference.upload(request), also send the PHPSESSID via a query string parameter:

                            Example: fileReference.upload ( /php/uploadFile.php?PHPSESSID=123xyz12es8dlksi, "file" );

                   

                  3. Within  /php/uploadFile.php, reset the session id:

                            Example: 

                                 if( isset( $_GET["PHPSESSID"] ) ) {
                                      session_id( $_GET["PHPSESSID"] );
                                   }

                   

                                   ini_set('session.use_cookies', 1);
                                   ini_set('session.use_only_cookies', 1);
                                   session_start();

                   

                  4. Now you have a valid session to upload the file and voila!