included directory setup

I have set up a website with the following files:

index.php
includes folder
pages folder

problem is that within my index.php code I have <?php include ('./includes/header.php') ?> to get my header which is in the includes folder…not the problem

The problem is that within the pages folder I have other php files that I want to retrieve the the header and footer.php from the includes folder from main directory and when I try to use <?php include ('./includes/header.php') ?>

I get this warning: Warning: include(./includes/header.php): failed to open stream: No such file or directory in C:\xampp\htdocs\interserv\pages\faq.php

So my question is how do I set this up to do this so I dont have to set up all files in each folder?

Go up one folder first

[php]<?php include ('../includes/header.php') ?>[/php]

I gave that a shot, and others too like …/…/ and …/…/…/ or …//…//…// or …/ or…//…/ nothing still get errors…and not using my_sql

Use the absolute file path. $_server[document root]

make sure the file actually exists in the folder the script is looking in, specially if the absolute path fails. Paths are relative to where the script is being executed from. If you’re including from the main index file in the root folder, then any page needs to use that as the base path. The only time that’s different is when its a cronjob, then its better to use the absolute path.

Sponsor our Newsletter | Privacy Policy | Terms of Service