Good point @ralph.m ;, it made me read the OP again.
Going back to the OP, you initially said this was your setup.
PHP Code:
mysite.com/index.php
mysite.com/includes/
mysite.com/category-1/demo.php
mysite.com/category-2/
mysite.com/category-3/
...etc
There is something I need to warn you about -- that is not how you would normally set things up, an includes directory inside your public website directory structure.
Include folders normally contain code which you do not want made public so you would normally have REAL (HDD) paths like this:
Code:
/var/www/mysite.com/index.php
/var/www/mysite.com/category-1/demo.php
/var/www/mysite.com/category-2/
/var/www/mysite.com/category-3/
(which of course appear as mysite.com/index.php etc once your server is configured correctly, much as @ralph.m ; is suggesting)
Then here is the shared place you would keep all of your include files:
Which would then be available to all of your websites.
(I am using /var/www/ as the default web folder, yours may look more like /xamp/public/http-docs/ or something ... it matters not)
Also, there is nothing stopping you have a folder WITHIN that /includes folder for just mysite.com
Then you can set the ini directive to tell PHP that all include files live at
Code:
php_value include_path "/var/www/includes"
This makes life really simple, all include files will initially be searched for in this directory.
Tradition would then have it that you would have say a file with all of your database connection credentials in a file for this project and name it:
and save it as:
/var/www/includes/mysite-config.php
You then include that file FROM ANYWHERE in your website PHP files with the simple instruction:
PHP Code:
include 'mysite-config.php';
Another example might be a really useful piece of PHP code which outputs variables for a date picker. You might use that in more than one project so you'd save it as /var/www/includes/date-picker.php and then from all your projects on different websites on this server you'd simple do:
PHP Code:
include 'date-picker.php';
You want to totally avoid mysite-config.php being accessible from your website, by someone stumbling across it in a publicly accessible folder such as mysite.com/includes/mysite-config.com
Personally, I prefer to set the include_path directive directly in the php.ini file, you will be able to do the same on your localhost server, but you'd need to check with your hoster if you get to have your own ini file, or if they are willing to set this variable up in your apache conf file for you.
Bookmarks