I need a help. I know how to share header via multiple pages if they are in main www_root directory. But I do not know if there is some best way how to do it if I want to share it across subfolders.
My example:
-- www_root
-- _inc
-- _partials
- header.php
- footer.php
-- assets
-- blog
- blog.php
-- organizer
- jobtodo.php
- edit.php
- delete.php
- index.php
I want to share header.php to index.php and blog/blog.php.
My current solution is:
$urisegments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))
if (count($uriSegmenst) < 3) {
require_once '_inc/sessions.php';
require_once '_inc/functions.php';
require_once '_inc/config.php';
.. rest of code
} else {
require_once '../_inc/sessions.php';
require_once '../_inc/functions.php';
require_once '../_inc/config.php';
.. rest of code
Is it good solution and is my folder structure ok?
Thank you for advices