; Windows: "\path1;\path2"
include_path = “.;C:\xampp\php\PEAR;C:\xampp\php\Zend;C:\xampp\htdocs\rpg_historian;”
Above you will find the address to my include path in php.ini on my xampp server. I want to be able to include files from a folder called “includes” that is nested in my project rpg_historian. In PHP when I use –
<?php include('includes/header.php'); ?>
The page works and loads correctly. However, if I click on a link that sends me INSIDE of includes/ I end up in a position where the page will state –
> Object not found!
>
> The requested URL was not found on this server. The link on the
> referring page seems to be wrong or outdated. Please inform the author
> of that page about the error.
>
> If you think this is a server error, please contact the webmaster.
>
> Error 404
>
> localhost 10/06/12 09:46:58 Apache/2.2.21 (Win32) mod_ssl/2.2.21
> OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
And my URL becomes http://localhost/rpg_historian/includes/index.php which is NOT where index.php is located. index.php is located in the root of rpg_historian. How do I go about setting up a system where I can easily set includes? I have tried the instructions located –
http://www.geeksengine.com/article/php-include-path.html
But for what ever reason even after setting the include path; It still doesn’t want to work correctly. Can someone explain to me how to set up a proper PHP include system that allows me to easily access files from folders? My understanding is that PHP is intelligent enough to cascade through folders to “find things” if set up properly.
The include path can either be absolute, i.e.:
Or relative (like you have at the moment). If it’s relative, then it’s relative to the file that’s including it.
Now, the usual solutions are either to include relative to the document root:
Or using some kind of pattern (like the front controller) to guarantee that the includes are processed in a consistent manner, then you can overcome the
include_pathdirective by either prefixing a dot to the path (likeinclude('./includes/header.php')) or by using a magic constant like__DIR__:Now, all of this is about includes, but your problem seems to be about generating links (otherwise you would never go inside the
includedirectory just by following an HTML hyperlink). In order to avoid this, make sure your HTML links point to the right place and not to the local (include) directory.