1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Unreliable Sessions - values not carried over

Discussion in 'PHP' started by sarahk, Jan 18, 2011.

  1. #1
    I have a script that collects emails for a collection of small, niche emailing lists. It runs on a number of wp websites flawlessly.

    Now one site is not saving the sessions.

    When the captcha is displayed the session stores the code (sometimes)
    When the form is submitted the session won't have the code to verify the form
    SEMrush
    I've got all sorts of debugging in there to see when its saved, lost etc and there is another working site on the same server so it wouldn't appear to be a hosting issue.

    Anyone have any ideas?
     
    sarahk, Jan 18, 2011 IP
    SEMrush
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    First off im assuming you have error_reporting set to its maxium level (E_ALL) (if you haven't already; please do) - and that its not reporting any errors?

    Heres some suggestions, on narrowing down the cause:

    - Try testing another script which uses sessions on that site (to distiniguish whether its script related or something else).

    - Compare the sites which are working; 'session.*' properties (within php.ini) to the site thats not working (and rectifty the properties accordingly).

    Possible causes:

    - It could be a browse issue, cookies disabled within browser (common problem with IE) - theirfore the session ID cookie is not being stored - so the session can not be read.

    - Ensure the 'session.save_path' (within php.ini) results to a valid/existing directory (usually /tmp).

    - Ensure nothing is sent to the browser before session_start().
     
    Last edited: Jan 18, 2011
    danx10, Jan 18, 2011 IP
    sarahk likes this.
  3. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #3
    It all depends on how the script works, doesn't it? Session data is stored on the remote server, and all it does is return a session id in the form of a cookie. Make sure your script is equipped to properly handle cookies. If you're using cURL, make sure you're using the CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE options. If you're using something like sockets, you will have to manually parse the cookies in the returned header and then send them with each request.

    edit: if you're treating cookies properly and are successfully sending the request, it sounds like an issue with the remote server.
     
    Alex Roxon, Jan 18, 2011 IP
    sarahk likes this.
  4. sarahk

    sarahk iTamer Staff

    Messages:
    26,758
    Likes Received:
    4,068
    Best Answers:
    115
    Trophy Points:
    665
    #4
    Yep, my instinct was that the server was at fault except that the second site on the shared server works. Because its shared hosting we don't have access to ini files or anything like that. No reason to think they'd be different.

    We're not doing anything fancy, it really is a very simple wordpress plugin. I've added the session start to the plugin as an init and that seems ok

    As for testing other scripts - I've run page1 and page2 as per the example http://www.php.net/session_start and apart from not liking SID (but did like session_id()) it worked just fine.

    I've had error_reporting turned on and while I get any number of errors they appear to be theme related or from the google analytics plugin.
     
    sarahk, Jan 18, 2011 IP
  5. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #5
    Hmm sometimes, to me rings bells, could be a timing issue ?

    Is the captcha related to how and when sessions are stored ?

    If so... might be worth a shot to add some kind of time delay between the session storing... just after the captcha is created and before sessions are stored
    time_nanosleep(0, 500000000); // 1/2 a second
    PHP:
    PHP reference time_nanosleep()
     
    MyVodaFone, Jan 18, 2011 IP
    sarahk likes this.
  6. sarahk

    sarahk iTamer Staff

    Messages:
    26,758
    Likes Received:
    4,068
    Best Answers:
    115
    Trophy Points:
    665
    #6
    I've got it fixed!

    Captcha turned out to be fine and didn't need work.

    Ultimately even though I was asking wp to start the session, or even when I did it in the first line of the script by the time I got to my function the session didn't exist. Within the function I needed to start the session and then all seemed to go well. Phew!

    thanks for your help :)
     
    sarahk, Jan 18, 2011 IP