Guardian-Mage Posted June 3, 2007 Share Posted June 3, 2007 I have one layout page that all directories use on my website. How can I make it so that no matter where the file is, the server will always include it. I cannot use direct paths because php will not allow it, and I can't specify the directory for each file. Example. Layout.php includes files/header.php which includes lib/main.lib. in Pages/Path/index.php I include ../../Layout.php. Than Layout.php's includes are all messed up If you can make sense of me, please help Quote Link to comment https://forums.phpfreaks.com/topic/54051-including-a-standard-file-in-all-directories/ Share on other sites More sharing options...
dough boy Posted June 3, 2007 Share Posted June 3, 2007 If your server allows it you can use a .htaccess file to modify the php.ini file to set the include path. Quote Link to comment https://forums.phpfreaks.com/topic/54051-including-a-standard-file-in-all-directories/#findComment-267228 Share on other sites More sharing options...
ted_chou12 Posted June 3, 2007 Share Posted June 3, 2007 try this: $page = $_SERVER['PHP_SELF']; $parts = explode("/", $page); $pos = 1; while (is_int(strpos($parts[$pos], ".php")) != true) { $path = "$path"."../"; $pos ++;} Ted Quote Link to comment https://forums.phpfreaks.com/topic/54051-including-a-standard-file-in-all-directories/#findComment-267236 Share on other sites More sharing options...
chronister Posted June 3, 2007 Share Posted June 3, 2007 If your pages include your layout page, then include the file in the layout page. I have struggled with this as well. All my pages in every site I build look like this... <?php include('header.php') ?> SOme Content here <?php footer() ?> In my include page, I generally have this line include('etc/includes.php') This makes all my pages have access to the includes file which contains sitewide functions and other items. Hope this helps ya a little Quote Link to comment https://forums.phpfreaks.com/topic/54051-including-a-standard-file-in-all-directories/#findComment-267340 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.