0

I'm trying to connect my PHP header from a file that is in a folder.

I'm attempting to do this by using:

<?php include("../header.php"); ?>

It works to bring the content in that file on the page, but its not applying the style.css file to the doc. Why?

Here is the contents of header.php:

<!DOCTYPE html>
<html>
<head>
    <title>%TITLE%</title>

    <link href='http://fonts.googleapis.com/css?family=Lilita+One' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" type="text/css" href="style.css">
    <link rel="stylesheet" type="text/css" href="includes/normalize.css">
</head>
<body>

<header>
    <div class="page-wrap">
        <h2 id="logo">Some Company</h2>
        <nav>
            <a href="index.php">Home</a>
            <a href="contact.php">Contact</a>
            <a href="rentals.php">Rentals</a>
            <a href="forsale.php">For Sale</a>
        </nav>
    </div>
</header>
<section id="mainContent">
2
  • open ur pges with firebug and see which CSS is not loading, and u will probably see why too Commented Sep 23, 2014 at 0:23
  • You should note that the <link> tag href property is relative to the file that is calling the include() and not relative to the header.php file. So, if you are loading somefolder/pages/page.php and you're including somefolder/header.php, you are fetching somefolder/pages/style.css and not somefolder/style.css. Just saying. Commented Sep 23, 2014 at 0:25

1 Answer 1

1

This is probably because its trying to reference the css at 'style.css' but try putting '../style.css'. It should allow the styles but it won't fix all your pages. In that case its better to use something like this:

<?php
    // Set a constant with your url
    define('BASE_URL', 'http://localhost:64411/TestingPHPStuff/');

    echo 'Now use it in your html like this:';
?>

<link rel="stylesheet" type="text/css" href="<?=BASE_URL;?>style.css"/>

That way file location does not matter.

Basically though, you are trying to use a stylesheet that doesn't exist at that current level. Probably.

Edited I changed it. If you include the 'http://' and the port ':64411' (for example you would use your port) then it should work. I just tested it and it only worked for me with both 'http://' and ':64411'.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm currently developing the site locally. When I define the BASE_URL as "localhost/someCompany/" it returns "localhost/someCompany/localhost/someCompany/index.php" When developing locally, do I simply define BASE_URL as "/"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.