I am trying to set a WWW_ROOT in order to reuse HTML code in different pages. This is an example of users.php using a header, where the CSS files are not found - 404 (Not Found) and I got Notice: Undefined variable: project_end in /Applications/XAMPP/xamppfiles/htdocs/lpweb/assets/php/initialize.php on line 11
Folder structure
>localhost
>lpweb
>index.php
>pages
>users.php
>assets
>php
>initialize.php
>header.php
>css
>bootstrap.min.css
initialize.php
<?php
define("PHP_PATH", dirname(__FILE__));
define("ASSETS_PATH", dirname(PHP_PATH));
$public_end = strpos($_SERVER['SCRIPT_NAME'], '/lpweb') + 7;
$doc_root = substr($_SERVER['SCRIPT_NAME'], 0, $project_end); //line 11
define("WWW_ROOT", $doc_root);
?>
header.php
<link rel="stylesheet" media="all" href="<?php echo WWW_ROOT . 'assets/css/bootstrap.min.css'; ?>"> />
users.php
<?php require_once('../assets/php/initialize.php'); ?>
<?php include(PHP_PATH . '/header.php'); ?>