Tips to simplify single-file relative path management
P粉649990163
2023-08-09 11:47:35
<p>How to manage relative paths in a project from a single file, since editing or updating is cumbersome and I would like to have a separate file to handle it. </p>
<pre class="brush:php;toolbar:false;">//Redirect to home page if role is user, otherwise redirect to admin dashboard
if ($_SESSION['role'] === 'user') {
header('location: ./../../index.php'); // this
} else {
header('location: ./../../admin/index.php'); // this
}</pre>
<p>Manage paths to a single file for the entire project</p>
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:Now you can easily include
config.php
in any file that needs to use the base path!