Jump to content
Larry Ullman's Book Forums

Recommended Posts

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

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

  • 1 month later...

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

  • 2 weeks later...

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

  • 2 weeks later...

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.

zz-Larry-1.jpg.c2214212b73f049ac89d4bb8b89dc653.jpg

 

zz-Larry-2.jpg.8a7940fec69cdef9d3c17a4cf77a2821.jpg

The database entry looks OK.

Cheers, Necuima

Edited by Necuima
added a little more info.
Link to comment
Share on other sites

  • 1 month later...

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

  • 2 weeks later...

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

  • 3 weeks later...

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

 Share

×
×
  • Create New...