How does thinphp5 write session? in the entry file

because you want to create an additional administrative entry, it is convenient to change the name of the entry file.

 app\admin\contrller\Login 

Login:

<?php
namespace app\admin\controller;
use think\Controller;

class Login extends Controller
{
    public function index(){
        if (!session("AdminLogin")) {
            header("Content-Type:text/html; charset=utf-8");
            $this->error("");
        }
        if (session("app.USER_AUTH_KEY")) {
            $this->redirect(url("/admin"));
        }
        return view();
    }
}
The purpose of

is to give a session, directly to the user when accessing the admin.php entry file so that he can determine whether it is entered from the entry file or not.
but the session (), of TP5 cannot be used directly in the entry file. If you use the $_ SESSION of PHP

@session_start();
$_SESSION["AdminLogin"] = 1;

then using session ("AdminLogin") in Login will not be available.
how can I use tp5"s session () in the entry file?

Mar.04,2021

thanks for the invitation. I know the general idea of the subject. I want to confirm which entry file the user enters from. @ Panda Sang, @ Shangguan Yuanheng all have a point. But I don't quite agree with the idea that the session function can only be executed after it is loaded automatically. It is only available after the introduction of the file helper.php. For the introduction of rules, take a look at the init method in\ thinkphp\ library\ App.php. So to use the session function, you can make the following changes in the entry file

  

because session () is loaded later

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b9ea21-50ab5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b9ea21-50ab5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?