Logging in manually - Cookie 'alc_enc' can't be set

Silverstripe Version: 4.4

I am trying to log a user in manually and I get the error: Cookie ‘alc_enc’ can’t be set.

Simplified code:

$member = Member::get()->filter(['Email'=>$email])->First();
$identityStore = Injector::inst()->get(IdentityStore::class);
Cookie 'alc_enc' can't be set. The site started outputting content at line 108 in /srv/users/*****/apps/****/public/app/src/PageController.php

Any clues on why this would be occuring?



What’s on line 108 of /public/app/src/PageController.php ?
Is it outputting some data deliberately? Could there be a closing PHP tag, with some whitespace after it?

1 Like

Thanks for pointing that out. It looks like any echo or print output before the logIn() will cause this error.

That makes sense. Any output will cause the response headers to be started, and PHP then can’t set the cookies.

It sounds like it’s too late to set a cookie / change the headers because content is already being sent. See this old forum post https://www.silverstripe.org/community/forums/general-questions/show/21467 perhaps you have some white space after a php closing tag somewhere?

p.s. @Anytech Victoria, Canada eh? I’m in Comox :canada::grinning_face_with_smiling_eyes: if you find yourself up island and want to chat SilverStripe let’s meet for a beer! https://jonomenz.com

Lol late to the party as usual. Don’t know how I missed that @Tim gave the same answer already!

1 Like

@JonoM Sure thing! I will try and remember next time I am up island.