|
OK, so the thing is that you are now accessing it via HTTP, which is different to what you were doing the first time and 99% of the time is absolutely wrong.
This is the best thing I can tell you: despite what a lot of people on forums think, including via HTTP is generally wrong and UNLESS you KNOW WHY you are including via HTTP, you should just include it via the file system.
So the reason the first example fails is because by including via HTTP you are NOT including the PHP code... you are including the parsed result of the PHP code. It includes the same output as if you were accessing it via the browser. From that you should be able to see that because you haven't handed the loc value to the script via HTTP in any way there is no way for it to know what you have set the loc variable to.
Now, regarding your 'deep directory' structure. If you don't want to have to use the '../../../../' and so on (and I can't blame you for not wanting to use it), look at the $_SERVER['DOCUMENT_ROOT'] variable. That will give you the filesystem path to your webserver root. So if you want to include the file 'include.php' in the directory 'includes' that is located in your webroot, no matter where the including file is you should just be able to use:
include( $_SERVER[ 'DOCUMENT_ROOT' ] . '/includes/include.php' );
Hope that all makes sense and helps... By the way, you will find there's another PHP 'issue' with including files via relative paths in the filesystem, so I always use something similar to the above to make sure that although I'm using an absolute path, I don't actually need to know the full path name...
|