1

I am beginner in php, trying to make one main.php file that incldes header and footer for the start

header.php

<html>
<body>
<div class="header">
logo, navigation etc
</div>

footer.php

<div class="footer">
Footer content here
</div>
</body>
</html>

and the main file

<?php include "header.php"; ?>
<div class="main content">
<h1> header </h1>
<p> paragraph </p>
</div>
<?php include "footer.php"; ?>

the errors:

Warning: include(header.php): failed to open stream: No such file or directory in - on line 1
Warning: include(): Failed opening 'header.php' for inclusion (include_path='.:') in - on line 1

Warning: include(footer.php): failed to open stream: No such file or directory in - on line 6
Warning: include(): Failed opening 'footer.php' for inclusion (include_path='.:') in - on line 6

all files are in the same foler and doing it on XAMPP

5
  • Which folder? A folder whose parent is htdocs? Commented Sep 16, 2012 at 22:13
  • .. So your files are in htdocs? Commented Sep 16, 2012 at 22:48
  • Are you sure they are named correctly and that it's not 'header.php.html' or something? Commented Sep 16, 2012 at 23:02
  • it does seem weard that Coda asks for permission to work with php file, but i did check they all were header.php with noraml extension Commented Sep 16, 2012 at 23:19
  • Well, I wish I had a better answer for you, but I have been unable to reproduce your problem. Commented Sep 16, 2012 at 23:38

3 Answers 3

1

Any file you are including must be in your include_path. Call get_include_path to see the current value.

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

3 Comments

The include_path already includes . (which is the current directory of the script) so the "No suck file" error is mysterious. My guess is an obscure permissions issue?
"which is the current directory of the script" - are you sure about that? try getcwd() first
I suppose it could be...you might have some weird umask and are creating files as not readable by all.
0

you should add your files in the same folder so they'll be in the same parent directory then you can use "include" to access them directly ex: in folder called Home there are 2 php files if i create a third one i could use this code "<?php include 'name of one the two other files found.php' hope its clear

Comments

0

If header, footer and main files are in the same directory, try this:

include dirname(__FILE__) . '/header.php';

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.