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);
$identityStore->logIn($member);
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?
Thanks
Tim
16 December 2019 23:19
2
Hi.
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.
Tim
16 December 2019 23:37
4
That makes sense. Any output will cause the response headers to be started, and PHP then can’t set the cookies.
JonoM
16 December 2019 23:38
5
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?
JonoM
16 December 2019 23:41
6
p.s. @Anytech Victoria, Canada eh? I’m in Comox if you find yourself up island and want to chat SilverStripe let’s meet for a beer! https://jonomenz.com
JonoM
16 December 2019 23:53
7
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.