Home > PHP Framework > ThinkPHP > body text

Verification code and session of Thinkphp6

藏色散人
Release: 2021-02-25 09:04:22
forward
2790 people have browsed it

The following is the tutorial column of thinkphp to introduce you to the verification code and session of Thinkphp6. I hope it will be helpful to friends in need!

tp6’s verification code and session

Today, when using the tp6 verification code, I did login verification. The verification code reports an error, and life and death prompts that the verification code failed.

After some testing, I found out that the tp6 session is not enabled by default. Need to manually uncomment.

Verification code and session of Thinkphp6

The relationship between verification code and session.

In fact, he saved the content of the verification code in the session, so if you use the verification code, you must open the session.

This is his Captcha class
You can see that he first injected a session class into the constructor to create a session object and save it. Later session operations will rely on this object.

Verification code and session of Thinkphp6

As you can see in his method of creating a verification code, he stored a 'captcha' key into the session through the session object.

Verification code and session of Thinkphp6

When he is verifying the verification code:

First get the verification code information stored in the session.

Verification code and session of Thinkphp6

This is why the session must be enabled when using the tp6 verification code. In the era before tp6, it was based on whether the session was enabled in your php.ini. In tp6, it encapsulates the implementation of session, so you need to manually open the session. Remember! ! !

The above is the detailed content of Verification code and session of Thinkphp6. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:segmentfault.com
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