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?