path - including php files in a header that is itself included in files in different folder levels -
ok, title little confusing structure of web site:
/ |--header.php |--page1.php +--css |--style.css +--subsection |--page2.php +--functions |--classes.php
right, both page1.php
, page2.php
include
header.php
. using relative file path whatever php page header.php.
header.php
includes other files; example css/style.css
, functions/classes.php
.
i might include them following:
<link rel="stylesheet" href="css/style.css"> <?php require_once("functions/classes.php"); ?>
this work page1.php
reletive paths correct. subsection/page2.php
fail paths should ../css/style.css
, ../functions/classes.php
remain defined in header.php
.
my question how can header.php use correct relative file paths includes regardless of file calling header.php
(e.g. apage.php
) located in web site directory.
set base path css /functions :
define('css_base','insert/full/path/here');
then access css in header.php using
<link rel="stylesheet" href="<?=css_base;?>/style.css">
Comments
Post a Comment