Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aurath's avatar

Manually creating a session w/ arbitrary ID

So I'm working on an API call (for internal purposes between two of our servers) that needs to receive a session id and then put some data into that session. So in the controller (I'm using API middleware, so no StartSession) I'm trying to manually start a session w/ an arbitrary ID. I've tried

Session::setId($id);

Session::start();

and:

App('session)->driver()->setId($id);

App('session')->driver()->start();

But neither are working. What's the best way to do this? Also, once the session is started this way can I just use session()->set() and forget? Or do I need to close it or something? BTW I'm on Laravel 5.2 and using redis for the session, if that matters.

0 likes
1 reply
aurath's avatar

Just noticed the value of the 'laravel_session' cookie was different from that of '_token' sitting in the session. Guess I'm missing something here.

It's probably just easier to curl over the session cookie on the server making the API call. I'll have to play with that.

Please or to participate in this conversation.