require file, skip if not found, require other file

my php sucks.

<?php require('../header.php'); ?>

If header doesn’t exist in directory than it needs to skip and look for it one directory deeper.

<?php require('../header.php' If unavailable, skip. '../../header.php'); ?>

how do I do that right? my page won’t load when it tries to load the header from the wrong directory.

Your header should be in one place. Set your path in your config file.

[php]$path = realpath(dirname(FILE)) . DIRECTORY_SEPARATOR;[/php]

Then in each page you want the header:

[php]require_once("./pathToConfig/config.php");
require_once($path . “folder/header.php”);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service