Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6873713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:06:12+00:00 2026-05-27T04:06:12+00:00

I have been having this issue when I use the php include() or require()

  • 0

I have been having this issue when I use the php include() or require() function. I will try and explain it as best as possible down here but let me know if it does not make sense. I am building a theme system where the main index.php has include ('themes/main/header.php') but there are errors when linking stylesheets and images. Here is how my directory is set out.

  • htdocs
    • index.php
    • themes
      • main
        • header.php
        • footer.php
        • images
        • css
        • js

Here is the contents of my header.php (striped):

<html>
    <head>
        <link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" />
    </head>
<body>
<div class="header">
<img src="images/logo.png" />
</div>

When I load up the main index.php the stylesheet and images are not able to be found. I know this is because the header file is brought into the index.php file but is there a way around this? Thank you so much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:06:13+00:00Added an answer on May 27, 2026 at 4:06 am

    I, for myself, use something like this:

    define(SITE_ROOT, '/'); //client side root of website
    define(SITE_PATH, '/var/www/mywebsite/htdocs/'); //serverside root of website 
    
    function url($relative, $startingFrom = false, $echo = true) {
        $r = '';
        if($startingFrom === false) {
            $r = SITE_ROOT . $relative;
        } else {
            $forward = str_replace('\\', '/', $startingFrom);
            $path = substr($forward, 0, strrpos($forward, '/'));
            $r = SITE_ROOT . substr($path, strlen(SITE_PATH)) . '/' . $relative;
        }
        if($echo) {
            echo $r;
        } else {
            return $r;
        }
    }
    

    in short, this builds a “site absolute” path for you, this way you could also change the name of your “theme” without having to change all absolute references it contains.

    this way, in header.php you can write:

    <link rel="stylesheet" href="<?php url('css/layout.css', __FILE__);?>" type="text/css" media="screen" />
    

    the function has several optional attributes, they should be self explanatory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having this issue in iterating through an array of keys and
I have been having this issue for a while now and I cannot seem
i have been having this issue for some time now, and have not gotten
We have been having some debate this week at my company as to how
Hello I have been having trouble with this for a while now. I have
This is a really weird problem that I have been having. When I download
I have been struggling with this for quite some time having been accustomed to
I have been trying to tackle this problem , but I am having difficulty
No doubt elements of this question have been asked before, but I'm having trouble
I have been having some problems trying to get my PHP running. When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.