设置常量以重用HTML

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'); ?>

You are mixing $public_end and $project_end

Also after reviewing your code from GitHub I believe this will work for you.

define("WWW_ROOT",$_SERVER['REQUEST_SCHEME']."://".$_SERVER['HTTP_HOST'].rtrim($_SERVER['REQUEST_URI'],'/'));

Alternatively, you can use the relative path to refer to CSS files which will make your life easy

<link rel="stylesheet" media="all" href="assets/css/bootstrap.min.css" />