Laravel is a PHP framework. When using laravel, you will encounter session usage problems. At work, the session default file cache is used. After using it, I found session()->put("key ","values")
was not set successfully. Finally, I checked the source code and found that when using file caching, I need to use the save()
method to persist it to the database.
Source code: vendor/laravel/framework/src/Illuminate/Session/Store.php
/** * Save the session data to storage. * * @return bool */ public function save() { $this->ageFlashData(); $this->handler->write($this->getId(), $this->prepareForStorage( serialize($this->attributes) )); $this->started = false; }
Due to the use of file caching, the source code of the write method call: vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler.php
/** * {@inheritdoc} */ public function write($sessionId, $data) { $this->files->put($this->path.'/'.$sessionId, $data, true); return true; }
Related recommendations:
Laravel 5.4 session validity issue
How does php session write to redis
Detailed explanation of PHP's session deserialization vulnerability
The above is the detailed content of What to do if the session is not saved successfully in Laravel 5.4.36. For more information, please follow other related articles on the PHP Chinese website!