#1 November 26, 2018 8:21am

Terrra-Robin
Member
Registered: February 7, 2016
Posts: 61

Reusable functions sending headers in utils.php?

Hi,

I'd like to make a function that checks if there's a cropped image.
If not, use the uncropped image. If there's no uncropped image either, use a placeholder image.

I thought it was a good idea to put this inside custom/inc/require/utils. I place all small reusable custom functions in here.

But now I get a waring / error message "cannot send session cookie. headers already send etc. etc." and the whole site doesn't work.
I've had that problem with more cases. For example when doing a require to a vendor /composer folder that does an api call or db request.

So I was wondering: what's the proper place / way to place these kind of functions mentioned above in Bigtree?
I could just include everything in a layout, but probably there's a more elegant way that I don't know of.

Thanks in advance!



EDIT: any empty lines or things before opening  php inside an inc/required file break the site or result into a warning.
Never had this issue before... So it might be a bug.

Last edited by Terrra-Robin (November 26, 2018 8:28am)

Offline

#2 November 26, 2018 11:14am

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 978

Re: Reusable functions sending headers in utils.php?

It's possible your environments before defaulted to having output buffering turned on. Since /custom/inc/required/ is included in bootstrap and output buffering isn't turned on until after bootstrap is executed, any errant new line output from a /custom/inc/required/ file will likely cause sessions to fail to start. Are you using the new database session handler? It's possible that handler is less tolerant and won't silently fail.

Offline

#3 November 27, 2018 4:46am

Terrra-Robin
Member
Registered: February 7, 2016
Posts: 61

Re: Reusable functions sending headers in utils.php?

timbuckingham wrote:

It's possible your environments before defaulted to having output buffering turned on. Since /custom/inc/required/ is included in bootstrap and output buffering isn't turned on until after bootstrap is executed, any errant new line output from a /custom/inc/required/ file will likely cause sessions to fail to start. Are you using the new database session handler? It's possible that handler is less tolerant and won't silently fail.

Thanks again Tim! I had an old environment file without the session_handler entry in it.
When I put "db" in it, it seems to work perfectly fine:)

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.