I am new to php and facing initial problems :).
My directory structure is as follows :
site
index
homepagesections.php
assets
css
style.css
config
db.php
include
header.php
index.php
In the index.php , which is in the root folder I need to include the header.php file which includes config/db.php and also assets/css/style.css.
I have tried all the options ( including. the DIR option ) but failed. What is the best way to include these files and also the path for the style.css ?
In index.php path to header is include/header.php:
include('include/header.php');
In header your path to db.php is ../config/db.php so you will have:
include('../config/db.php');
Note '../' - this is how you navigate 1 level up, from the directory your file is. In header adding css will be something like:
<link rel="stylesheet" href="../assets/css/style.css">
In index.php:
include (__DIR__.'/include/header.php');
In header.php:
include (__DIR__.'/../config/db.php');
include (__DIR__.'/../assets/css/style.css');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.