In the tags. php Directory of the application directory (a new one is created without a fixed name and cannot be changed), the behavior is bound to a tag. here it is bound to "CheckAuth"
Directory structure:
1. create UserCheck. php under the user \ behavior Directory (the name can be used as needed)
Error ('log on! ', 'Index/login ');}}
Here, the run function adds the logic for checking user permissions. you can use session or other...
2. in the tags. php directory under the application directory (if no one is created, the name cannot be changed), bind the behavior to a tag. here, it is bound to "CheckAuth"
[ 'app\\user\\behavior\\UserCheck', ],];
3. write the listening tag code where the controller needs to listen
User \ controller \ Index. php
The above is the code shared by ThinkPHP5 development (3) using Behavior to detect user logon status. For more information, see other related articles in the first PHP community!