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

tealiedie's avatar

Session is not persisting on server

Hi, i'm having a weird bug or issue about persisting sessions, lets say i manually authenticate the user in HomeController@index using

Auth::attempt(['user' => 'username', 'password' => 'password']);
// or
Auth::login(User::find(1));

but when i navigate to 'HomeController@create' or 'HomeController@edit' the authenticated user is not there. also i tried also setting the controllers middleware to redirect users if not authenticated to 'HomeController@index'.

//HomeController
public function index()
{
 Auth::attempt([
  'username'=>'username',
  'password'=>'password',
 ]);
}

//OtherController
public function __construct()
{
 $this->middleware('auth');
}

in my local machine, it works fine, but when i upload it on the server, it's not working anymore.

i also checked the storage/framework/sessions and the file is there. both local and server.

also tried setting the config/sessions driver to file, database, cookies. but none of these works. i tried clearing the browser's cookie, setting the storage/framework/sessions folder permission to 777, and still no luck. i also tried setting the config/session lifetime to 120 expire_on_close to true, still no luck. i check my laravel version is 5.0.35 and php version is 5.4.28, i'm wondering if the php version has something to do with the sessions,

please help.

0 likes
14 replies
tealiedie's avatar

i run php 5.5.19 on my local machine, server php 5.4.28, apache version 5.4.28

the weird thing is, i also have another project on that server, but it is running just fine, configurations are the same with my faulty project on server, i dont know what couldve happen, i also tried using database, 'file', cookies. also check if there files / data storing, and it has!. files, data in sessions table. cookies, all was there.

SaeedPrez's avatar

Another Laravel project, same Laravel version?

I've also noticed you're using username instead of email, can I assume you have changed your code to work with that?

I think the most common session problem is no web middleware or double web middleware, but that's usually Laravel 5.2.

Try some simple tests to see if the session is really working or not..

Route::group(['prefix' => 'test'], function() {

    Route::get('session', function() {
        Session::put('testing', 'Hello World');
        return redirect('test/session-result');
    });

    Route::get('session-result', function() {
        return Session::get('testing');
    });

});

Then visit http://yourdomain.com/test/session and see what happens.

chintan's avatar

Please make

 'domain' => null,

in config/session.php

tealiedie's avatar

@chintan hi, sorry for late reply, im in a different project for last three weeks, seems 'domain' => null, didnt fix the problem.

tealiedie's avatar

@SaeedPrez hi, it's not showiing the "Hello World".

PS: i also checked the folder inside /storage/framework/sessions/, the file session was there,

psbharathy's avatar

@tealiedie

Could you try add your domain in the config/session.php

'domain' => null,

into 'domain' => <your_hostname>,

jlrdw's avatar

Is local windows? If so remember linux is case sensitive.

VinoNeha's avatar

Did u fixed the issue...? Im facing the same issue please let me know how did u fix ur problem

Please or to participate in this conversation.