ackerchez
ackerchez

Reputation: 1756

Laravel Session Data getting rewritten

I have a weird situation happening. Here is my code:

public function getHomepage(Request $request){
    $data['testimonials'] = $this->getTestimonials();
    session()->put('location', 'north_america');
    \debugbar()->info('UPDATED SESSION');
    session()->save();
    return view('site.index')->with('data', $data);
}

public function getGlobalPage(Request $request){
    $data['testimonials'] = $this->getTestimonials();
    if(session()->has('location')){
        session()->forget('location');
    }
    session()->put('location', 'global');
    session()->save();
    return view('site.global')->with('data', $data);
}

public function getFeaturesPage(Request $request){
    //\debugbar()->info($request);
    //echo session()->get('location');
    return view('site.features')->with('data', []);
}

Here is what happens. When I go to the "home" page, the session variable for "location" comes back as "north_america". That is good.

If I move from the "home" page to the "global" page the session variable for "location" comes back as "global". That is good too.

If I then move from the "global" page to the "features" page, the session variable for "location" is coming back as "north_america". It is not getting set to null or something, it seems to be rewritten. How can that happen?

Here are the routes:

Route::get('/', ['as' => 'site.home', 'uses' => 'Site\SiteController@getHomepage']);
Route::get('features', ['as' => 'site.features', 'uses' => 'Site\SiteController@getFeaturesPage']);
Route::get('global', ['as' => 'site.global', 'uses' => 'Site\SiteController@getGlobalPage']);

Upvotes: 1

Views: 107

Answers (1)

ackerchez
ackerchez

Reputation: 1756

Figured it out. When the browser was trying to get a missing image it was receiving a 302 redirect for the image. This was hitting the route which was changing the session variable even though the browser page was not moving.

Upvotes: 1

Related Questions