I've made a website that uses popups. I know this may not be the best approach, but it was a wish from the customer. After logging in, when a button is clicked that opens a new window via the window.open() JS function, the popup window seems to loose the login session completly. Sometimes it works, sometimes the session is lost, the user is considered not to be logged in and the process die()'s. Printing the session says:

Array
(
)

This never happens to me personally, and that makes it difficult to debug. I use a mac, but I've tried to reproduce this on a windows machine without success. From what I've found, later browsers starts new processes for new tabs and popups in order to minimize mayhem when a process crasches. For my customer this happens in both IE, Firefox and Chrome.

Is there anything you can do, PHP-wise, to prevent this? Any ideas?

    Does your pop-up have session_start() at the top?

      Yes.

      the popups and sessions ALWAYS works for me, and SOMETIMES works for my customer. My theory is that popups are run in new processes depending on a number of things, eg available memory. When a new process is used, a new session is used. I'm not sure this is the problem, but it is all I've got to go on right now.

        How do you specify the URL for the pop-up window?

        Unless you modify the default behavior, cookies set for "mydomain.com" are not set for "www.mydomain.com", thus if your customer is using "mydomain.com" to access the website yet your popups specify a URL using "www.mydomain.com", their login cookie would not be available in the popup.

          I use local paths, like this: /admin/productEdit.php?ProductID=123

          This is an example of code used on the actual website:

          <input class="ui-button ui-widget ui-state-default ui-corner-all" type="button" style="margin-right: 1em" name="cloneProductButton" onclick="window.open('/admin/productEdit.php?cloneID=43', '', 'status = 1, height = 800, width = 1000, resizable = 1, scrollbars=1');" value="Klona produkten" role="button" aria-disabled="false">

            Then I would say it's a browser issue, since I'm assuming that you're using cookies to propagate the PHP session ID from one page request to another. Thus, the real crux of the issue is why isn't the customer's browser always sending the cookie for the pop up windows.

              All I do to initialize the session is to run session_start() at the very top of the script. Then I look for a few certain things in $_SESSION to determine of the user is logged in or not. If not, the script dies. Hence the blank page as a result.

              I'm not very familiar with sessions and cookies to be honest. As far as I know, a session is just like a cookie, but it's never saved to disc on the client. Session data exists in the memory on the server. A Session ID is all that is sent between the client and the server. Correct?

                How about session timeout and cleanup? Could it be that you never get it because you try cliking your way through the popups quickly while the customer sometimes wait too long before sending the next request?

                  No. If the customer reloads the main window it works. The session times out after an hour and this can happen immediately after login.

                  What bugs me is that this does not seem to be a common problem. There's not much information about this.

                    You could try gathering more information.

                    Have you tried logging and inspecting request and response headers, especially for the requests where things fail? It is of course entirely possible that the problem actually originated in the request priot to where the problem appears, so you might have to log all requests/response headers. Then, when something fails, at least you have the time of failure so that you can limit how much you have to wade through backwards.

                    If you also store information about what customer this regards and can get the customer to let you know the next time the problem appears, you will have very little data to check in the end.

                      a month later

                      I'm pretty sure that does not have anything to do with the problem. The browser seems to decide all on its own if a new session is to be used by a popup window.

                      It seems a bit strange that I cant find any info on this anywhere. Am I the only person in the world to use popups that depend on a session...?

                        Write a Reply...