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.

 

Link to comment
Share on other sites

 

 

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" />
Link to comment
Share on other sites

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>
Edited by glassfish
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.