P粉3402642832023-08-10 10:54:24
For example, create a new file and name it config.php
(or any other name you like) and write these lines in it as follows:
<?php //`__DIR__` 是一个代表当前脚本所在目录的魔术常量 //根据您的项目结构,调整路径拼接(`BASE_PATH .`)。 define('BASE_PATH', __DIR__ . '/'); ?>
Now you can easily include config.php
in any file that needs to use the base path!
<?php require_once 'config.php'; if ($_SESSION['role'] === 'user') { header('location: ' . BASE_PATH . 'index.php'); } else { header('location: ' . BASE_PATH . 'admin/index.php'); } ?>