I start to work with my project using laravel 5. I realized that it work fine in my local directory with session after I login to my site, But I just know that I got problem when I hosted my project to server. After I login each time, the session could not remember that cause the problem to me.
public function postLogin()
{
$hit = 0;
if(Request::ajax()){
$pw = Request::input('pw');
if(!empty($pw)){
$admin_pass = AdminPassword::first(['admin_pass']);
$ip_address = Request::ip();
if(!empty($admin_pass) && trim($admin_pass->admin_pass) == trim($pw)){
if(Auth::attempt(['username' => Request::input('username'), 'password' => Request::input('password'),'status'=>1])){
try{
$user = Auth::user();
$user->last_login = date('Y-m-d H:i:s');
$user->login_ip = $ip_address;
$user->save();
$permissions = Auth::user()->permission;
if(!empty($permissions) && count($permissions) >0){
session(['ROLE_PERMISSION'=>$permissions]);
}
$failed = FailedLogin::whereRaw('ip_address = INET_ATON(\''.$ip_address.'\')')->first();
if(!empty($failed)){
$failed->delete();
}
}catch (\Exception $ex){}
$url = Request::session()->pull('url.intended', '/');
return ['url'=>$url,'msg'=>'Successfully.','status'=>true,'hit'=>$hit];
}else{
$hit = $this->updateFailedLogin($ip_address,Request::input('username'));
}
}else{
$hit = $this->updateFailedLogin($ip_address,Request::input('username'));
}
}
}else{
return redirect()->route('login');
}
return ['url'=>'','msg'=>'Try again.','status'=>false,'hit'=>$hit];
}
Please help me out from this.
Thank you very much.
In your App\Http\Controllers\LoginController. php we will change our login method and implement the remember me. As you can see above I added $request->get('remember') to the second parameter of Auth::login() function.
If you just want to see contents of session, try dd() : dd(session()->all()); If not, just use this to get all info: $data = session()->all();
file - sessions will be stored in storage/framework/sessions . cookie - sessions will be stored in secure, encrypted cookies. database - sessions will be stored in a database used by your application.
If this works perfectly locally and not only its probably one of two things. 1) you need to set permissions on your storage folder to be writable. 2) when you login locally on the browser and it saves your cookie, if you try to log in online it logs you out locally because its the same cookie basically but point to different domains. So you probably should use different browsers if you want to work locally and online at the same time
Use below code
setInterval(function(){
$.get('/my/ping/route');
}, 1000 * 60);
.ajaxError()
What you can try is Session:save(); It solved my problem where session has not been carried over when redirecting user to payment gateway.
From what I heard it is caused by some interruption in HTTP request.
If the error logs in storage/logs don't give any clues about issues such as directory permissions, check your .env file on your server for the SESSION_DRIVER variable that is loaded in config/session.php to make sure you have the right persistence mechanism based on your server configuration (file, cookie, database, apc, memcached, redis, etc.).
If that doesn't help, check the config/session.php file. I've seen someone set the lifetime property to 0 thinking that this would make sessions indefinite, but in reality it caused the issue that you're having.
Please check how you are storing your session.
By default laravel uses file-based ( storage/framework/sessions
), make sure the directory is writeable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With