SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP session and AJAX

    Hi

    I have a strange problem which is occurring with AJAX. I run a PHP page which I pass it some variables using AJAX which works fine. The problem I have is $_SESSION does not work. I start the session the same way very page which works fine although for some reason when using AJAX to run a page, $_SESSION does not work.

    The code works fine on all browsers (FF, IE, Safari, Opera etc) although the error does not occur often. When it occurred the browser was IE although I do believe the browser is one which has been optimised/adapted.

    Any help would be most gratefully appreciated as I cannot even create the error myself.

    Thanks
    p_h_p

  2. #2
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    988
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    Is your php installation running suhosin?

    I hit an issue where suhosin was using the user agent to encrypt the session. In IE8 if you have compatibility mode on, the UA for the page is IE7 but for the request is IE8 the solution was to turn off suhosin.session.cryptua

  3. #3
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Thanks for the reply.

    suhosin is not installed.

    One extra thing to note is that the browser is IE7 although I believe IE7 has been optimised by a well known ISP.

    IE7 works fine so its not an IE issue, it is a problem which I guess is because of some changes or settings in the optimised IE browser.

    Any help is much appreciated as this has me baffled.

    Thanks

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would do some logging to see if the session cookie is being sent. I assume $_SESSION "doesnt work" means that the $_SESSION array is empty, when there should be data in it? Or is the problem that adding new data doesn't get saved?

    There's also a possible race condition. Normally, using the default files save handler, php will manage concurrency and only allow a single script access to a given session at a time. There's some things that can make it not work right.

    Since you know the user agent string of this special IE, I would look at your access logs to see if you see anything odd, paying careful attention to the timestamps of each request. You might do some of your own logging to supplement it if needed.

  5. #5
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Thanks for your reply.

    $_SESSION has values already set so all I am trying to get is those values. I start the session as normal but for some reason some customers $_SESSION is empty I guess the session has not started. The main page has started the session then AJAX is used to run a different PHP page which starts the session and uses $_SESSION although this is the page were the problem exists as $_SESSION is empty.

    I have checked all the logs and there is nothing relating to this error.
    Is it possible for the session to be locked on one browser and not another as the problem does not exist on all other browsers?

    I cannot replicate the error so its difficult to find a solution at present.
    If the session is locked what solution do I have, is it possible for me to unlock the session before using AJAX?

    Thanks

  6. #6
    SitePoint Evangelist
    Join Date
    Jun 2005
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We might be able to help better if you post some code...you must be losing the vars somewhere.

    e39m5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •