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 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?
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().
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.
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.
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()
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