andris
andris

Reputation: 99

php include gives error

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

Upvotes: 1

Views: 2696

Answers (3)

Jos&#233; Carlos PHP
Jos&#233; Carlos PHP

Reputation: 1489

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

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

Upvotes: 0

Hussein
Hussein

Reputation: 1

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

Upvotes: 0

AJ.
AJ.

Reputation: 28194

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

Upvotes: 1

Related Questions