PHP newb here. I'm creating a website and I'd like to include my css stylesheets on each page using a php include. My site has many page at diferent folder depths, which can be a problem. After some research, I learned that I can include the php file from any folder depth by using the following syntax:
Code: Select all
<?php include($_SERVER["DOCUMENT_ROOT"].'/_includes/components/stylesheets.php'); ?>Code: Select all
<link rel="stylesheet" type="text/css" href="_includes/css/main.css" />
<link rel="stylesheet" type="text/css" href="_includes/css/navigation.css" />Code: Select all
<link rel="stylesheet" type="text/css" href="<?php echo $_SERVER["DOCUMENT_ROOT"] ?>/_includes/css/main.css" />
<link rel="stylesheet" type="text/css" href="_includes/css/navigation.css" />So what am I missing? While putting $_SERVER["DOCUMENT_ROOT"] into my path to my css file might work, it seems like a really inefficient way to handle includes. Is there a better way?
Thanks in advance,
jeff