Home > Backend Development > PHP Tutorial > What to do if the session is not saved successfully in Laravel 5.4.36

What to do if the session is not saved successfully in Laravel 5.4.36

小云云
Release: 2023-03-20 11:00:01
Original
1414 people have browsed it

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;
 }
Copy after login

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;
 }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template