php include wont pick up the header file

Hi all
I am a php beginner. I’m busy trying to run through some tutorials.
I have some php script which is using “include” to locate a header file, however the include statement is not finding that header file.
I am currently working on my home computer just running through online tutorials so nothing is saved on an external server…

The php line I use in my “homepage.php” file is as follows

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

The file it looks for is header.php in the Inc folder but it cant seem to locate it.

The “homepage.php” file runs successfully, but does not pick up the header file it is looking for.

If I run the “header.php” file on its own it works…

Does anyone have any ideas?

if the directory Inc is off the root all you have to do is [php]include “Inc/header.php”;[/php] and also make sure the directory is Inc (capitalization is correct) is correct, if you’re running this on Windoze Linux/iOS (Oops Brainfart) :D. An like already stated it’s best to keep directories and files lowercase (Except maybe Classes).

BTW I locked your other thread and I’m assuming this is your account that you want to use, no need for two threads being the same.

Everyone sets their directories differently, but this is how I set mine up.
lib/classes
lib/css
lib/functions
lib/includes
lib/js
lib/images
lib/views
lib/website_project

Correction, capitalization is important for Linux, Windows doesn’t care about it for files or directories.

Your current listing is going up a directory, then Inc, then the file.

You should get in the habit of always using lowercase. File names, folder names, variables etc.

  • Variables can be camelCase but it is my opinion under_score is easier to read.

Hi All
Thanks very much for the replies, so I have made the changes suggested, I’ve renamed “Inc” to be lower case and copied in the suggested “include” statement, but still no luck…

I’ve attached the homePage (saved in my root folder) and the header code (saved in the inc folder)…

I’ve tried so many different permutations but the homepage just does not pick up the header…
Is there maybe a setting I need to change? Both these files seem to work independently

Thanks again all.

PS. thanks for deleting the other post, your assumption was correct


header.txt (696 Bytes)

homepage.txt (1.15 KB)

Turn error reporting on. If it is not being included it means it isn’t finding the file. Instead of using include, use require and see if the page still works.

You are already mixing case. Your header is lower case, but your footer is not. This is why you need to be consistent and ALWAYS use lower case.

Additionally, your footer is ./ but your header is /

Use ./inc/header.php and ./inc/footer.php

Hi there
thanks again for the replies

Kevin…I have now put everything in lower case and I have also decided to just include the header.php file and the footer.php file in the root folder to simplify the include statement and avoid having to look in other folders…but still nothing…everything I do brings the same result

my include statements now look as follows…I tried with brackets and “” as well.

<?php include 'header.php'; ?>
	<div style="width: 600px; margin: 0px auto 0px auto;">

<?php include 'header.php'; ?>

I have tried to use another very simple example from the w3schools tutorial at the following link

http://www.w3schools.com/php/php_includes.asp

even when copying that very simple example - it is giving me the exact same problem…

Is there no setting or something that I need to adjust to get php to work?

I am coding in notepad++

My apologies again, I am a rank beginner…
Thanks again

In response to astonecipher…could you please provide me with some error reporting code to use…
I tried the following which I got online but it didn’t bring about any errors…

ini_set( ‘error_reporting’, E_ALL );
ini_set( ‘display_errors’, true );

I told you what to do already. Your still doing / instead of ./

Thanks, but I have tried ./
I’ve just tested all of the below…but none worked. Am I still missing something…

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

(adjusted similarly for footer as well)

So I’m sure there is a more general problem here. I’ve tried the following simple code and it produces a blank page…

<?php echo "My first PHP script!"; ?>

The code within the php tags does not seem to be working regardless of what is in there…

Ok Don’t stress, I think I’ve figured it out.
Apparently php needs a server to interpret and run php code, it doesn’t work like a normal html page…
As I said I am a beginner…
I am going to download and install xampp
Thanks for your guys responses…

OMG!, Yes, php needs a server with PHP to run PHP files.

Me never thought to ask if OP was using a local server…LOL :smiley:

Sponsor our Newsletter | Privacy Policy | Terms of Service