Necuima Posted October 11, 2019 Share Posted October 11, 2019 Hi Larry, I have been using your database session handler for quite some time now in my Windows 7 environment but have run into a problem when I try to use it in a new PC set up with Windows 10 and Apache/PHP 7.3.7 (64 bit). I keep getting an error: "An error occurred in script 'C:\xampp\htdocs\....php' on line 53: session_write_close(): Session callback expects true/false return value" and I am getting this error everywhere that I have used 'session_write_close()' as per page 95 of the book (that's in dozens of places). Is it perhaps not needed in Win 10 with a fairly current Apache/PHP install? Or do I need to code it differently? Any advice will be most appreciated and thanks in anticipation. Link to comment Share on other sites More sharing options...
Necuima Posted October 11, 2019 Author Share Posted October 11, 2019 I checked with the PHP manual and from PHP 7.2 the return from session_write_close() is a Boolean rather than a void. Might this require an update to the session code in the book? I tried just adding $rc = session_write_close() but I'm still getting the error. Thanks, Necuima Link to comment Share on other sites More sharing options...
Larry Posted October 11, 2019 Share Posted October 11, 2019 I'll look into this and get back to you after the weekend! Link to comment Share on other sites More sharing options...
Necuima Posted November 19, 2019 Author Share Posted November 19, 2019 Hi Larry, Have you had a chance to have a look at this yet? Thanks, Necuima Link to comment Share on other sites More sharing options...
Larry Posted November 23, 2019 Share Posted November 23, 2019 Sorry about the delay and thanks for reminding me! The solution here isn't immediately obvious so I had to hunt around a bit. It looks like the write session function is what comes into play here (per the PHP manual), but that method returns true, assuming we're looking at the same script. This is a wild guess, but does it get fixed if the close session function is changed to mysqli_close($sdbc); return true; Link to comment Share on other sites More sharing options...
Necuima Posted December 5, 2019 Author Share Posted December 5, 2019 Hi Larry, This time it is me that is sorry re the delay in responding. I have just started changing over from Win 7 to Win 10 which is inhibiting my ability to test your proposed solution. I have a LOT of stuff on the Win 7 PC so am taking it very carefully - bit by bit - as I make the change to the (separate) Win 10 PC. Also am making the change from Windows Live Mail to Outlook and that's not as straight-forward as one might imagine especially as I want to migrate all my email storage folders over to Outlook. I will test your suggestion as soon as I can but it might be a couple of weeks before I can - and please accept my apologies for my tardiness. Cheers from Oz. Link to comment Share on other sites More sharing options...
Larry Posted December 8, 2019 Share Posted December 8, 2019 Absolutely no problem. Do what you have to do. Sorry I didn't have a better answer for you in the first place! Link to comment Share on other sites More sharing options...
Necuima Posted December 20, 2019 Author Share Posted December 20, 2019 (edited) Hi Larry, Finally got to a point where I could try your suggestion. Sadly, if I applied your suggestion correctly, it did not solve the issue. Please see the attached. The database entry looks OK. Cheers, Necuima Edited December 20, 2019 by Necuima added a little more info. Link to comment Share on other sites More sharing options...
Necuima Posted December 20, 2019 Author Share Posted December 20, 2019 (edited) P.S., the script is your script 'sessions.php' just renamed and on your original it is line 53. Up top I just added As per your 'advanced' book. Edited December 20, 2019 by Necuima added some more info Link to comment Share on other sites More sharing options...
Larry Posted January 26, 2020 Share Posted January 26, 2020 Okay, I just installed the DB and script and upgraded PHP to 7.3.8. Sadly, I am NOT seeing the error at all. This is using PHP's built-in server, although it'd surprise me if this was an Apache issue. I'm also testing this on a Mac. Unfortunately it's really hard for me to come up with a solution without being able to replicate the problem. From everything I'm reading online, having the _destroy() return a boolean solves the problem for some, but of course the code in the book already does that. Link to comment Share on other sites More sharing options...
Necuima Posted February 7, 2020 Author Share Posted February 7, 2020 Hi Larry, Thanks for this. I have been having computer troubles and am having to re-build ALL my software from a clean Win 10 installation. Fortunately I have great backups :-) I'll test again when I have re-installed XAMPP. Thank you for following this up. Cheers from Oz, Necuima Link to comment Share on other sites More sharing options...
Necuima Posted February 24, 2020 Author Share Posted February 24, 2020 Hi Larry, I finally got to the point in my complete software re-load/re-build where I could test your suggestion. I re-downloaded the script from your website and made the suggested change but unfortunately I am still getting the error "on line 29: session_write_close(): Session callback expects true/false return". Here is my modified code: // Define the close_session() function: // This function takes no arguments. // This function closes the database connection. function close_session() { global $sdbc; mysqli_close($sdbc); return true; // return mysqli_close($sdbc); } // End of close_session() function. My environment is XAMPP 7.3.5 with PHP 7.3.5 both 64 bit under Windows 10 (64 bit). I know that you are a very busy man so please treat this as low priority - I will use a work-around. Best regards, Necuima. Link to comment Share on other sites More sharing options...
Recommended Posts