3 years ago

Session values lost after redirect

Posted 3 years ago by Rens

I have to issue a redirect using the native PHP way, as I'm depending on an external library. When I write values to the session before doing the redirect using header(), they are lost after the request has been redirected.

function someLibraryFunction() {

    $request = request();
    $request->session()->put('foo', 'bar');

    // This does work: echo redirect('/get');
    // But this doesn't:

    header('Location: /get');

// These are web routes that have the relevant session middleware applied to them.

Route::get('/set', function (Request $request) {


Route::get('/get', function (Request $request) {

    print_r($request->session()->all()); // 'foo' is not set here.

NOTE: I've verified that session()-getId() is the same before and after the redirect.

Any ideas?

Please sign in or create an account to participate in this conversation.