Jump to content

Including the header.php File When Using a Sub Folder


glassfish

Recommended Posts

The root directory:

header.php

stylesheet.css

 

In the following example I am trying to include the header.php file in a sub folder.

 

When I include the header.php like in the following example then the stylesheet.css file will not work anymore:

<?php

include("../header.php");

?>

The stylesheet.css file is included in the head tags of the header.php file.

 

Is the above example the right way to do it? If yes, how can I do it so the stylesheet.css file will work too.

 

 

 

Is the above example the right way to do it?

Yes. That path is called a relative file path. This is how you include files from other directories.

 

 

 

If yes, how can I do it so the stylesheet.css file will work too.

Start your file paths in your HTML with a forward slash (this is know as an absolute file path) eg

<link rel="stylesheet" href="/stylesheet.css" />

When I use a forward slash the stylesheet.css file does not work at all anymore.

   <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        
        <link rel="stylesheet" type="text/css" href="/stylesheets.css" />
    </head>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.