Jump to content

Annoying ajax/php session problem


hedbanger83

Recommended Posts

Ok, here's my problem..

 

scenario 1:

In windows environment, with MSIE 6+, firefox 1.5+, Opera 9+, or Netscape 7+

--------------------------------------------------------

  • a user visits the root page (index.php) of the website.
  • the root page (at the very beginning) does a session_start();
  • Next (right after starting the session), the root page checks to see if $_SESSION['imgloaded'] isset. If it's not set, then the user's browser forwards to imgload.php (and it is NOT set, so the user gets forwarded).
  • imgload.php does NOT execute another session_start() (this particular page does not need any session variables). imgload.php now executes an embedded javascript function that preloads the images required for the root page.
  • When the preloader finishes, a function is run to make an Ajax request for the page, setimgloaded.php.
  • setimgloaded.php is a simple script containing the following.. <? session_start(); $_SESSION['imgloaded'] = 1; ?>
  • $_SESSION['imgloaded'] is now set to 1, and the ajax request completes, and forwards the user's browser back to index.php(root page)
  • index.php (root page) does another session_start(); then checks again if $_SESSION['imgloaded'] isset. And IT IS, so the user does NOT get forwarded again to the imgload.php page..and index.php loads completely.

 

All images are preloaded and ALL IS GOOD

 

scenario 2:

In Mac OS X, with firefox 2.0.0.3

--------------------------------------------------------

  • a user visits the root page (index.php) of the website.
  • the root page (at the very beginning) does a session_start();
  • Next (right after starting the session), the root page checks to see if $_SESSION['imgloaded'] isset. If it's not set, then the user's browser forwards to imgload.php (and it is NOT set, so the user gets forwarded).
  • imgload.php does NOT execute another session_start() (this particular page does not need any session variables). imgload.php now executes an embedded javascript function that preloads the images required for the root page.
  • When the preloader finishes, a function is run to make an Ajax request for the page setimgloaded.php.
  • setimgloaded.php is a simple script containing the following.. <? session_start(); $_SESSION['imgloaded'] = 1; ?>
  • the ajax request for this page never completes, and times out. Something goes wrong when trying to execute setimgloaded.php. And the user is never redirected to index.php again, because the redirection only fires upon completion of the ajax request.

 

ALL IS NOT GOOD!

 

Can anyone explain to me why this ajax request (in scenario 2) won't complete.. It has to be a php session issue in my eyes. Here's my reasoning. Remember how I said that imgload.php DOES NOT execute another session_start()? well, if I make it so it DOES, when the user initially get forwarded to imgload.php (from index.php, when $_SESSION['imgloaded'] is NOT set), imgload.php never loads at all, and the browser gets stuck at this second session_start();

 

TIA for any help on this.. It's driving me crazy....

 

- Kyle

Link to comment
Share on other sites

Hi,

 

My understanding is that if the session start is not at the beginning of the page the session data is lost.

 

I usually ensure that this is part of every page on a web that uses sessions, therefore I know I won't lose any session data. I have recently started using AJAX for a chat app that I'm writting and don't get an issue using sessions this way.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.