Jump to content

[SOLVED] Include from outside root. Works but Not??


Chris P

Recommended Posts

Ok. So I am trying to do an include for a file that is above the root of the website. Its actually part of a subdomain that I have.

 

I have default.php in the root of my site. It calls a file that is above the root in a different folder than site1.

This works like a charm.

 

I have another PHP file in a subfolder of the site1 that is trying to call the same file above the root. It doesnt work. stops parsing the file as soon as it tries to load.

 

	require($_SERVER["DOCUMENT_ROOT"].'/../blog.liquidarchaeology.com/wp-blog-header.php'); 

 

I have tried many variations on the above code but nothing will work. If I move said file to the root of the website then it works mint. But I cant have all my files in the root. Too messy for me.

 

Why is it that I can only access files above to root when processing a file in the root?

You can definitely include files outside of your web root. Your problem is the server variable that you are using.

 

Assuming you are on a Windows box, try something like :

 

$phpinc = "C:/Inetpub/phpincludes";

 

Then, in your code, replace $_SERVER["DOCUMENT_ROOT"] with $phpinc.

 

You'll need to make sure that the WebServer has at least Read access to this area on the server/pc.

It is probably an owner/permissions problem. What you do get if you add the following two lines in your main file immediately after your first opening <?php tag -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Not a windows box.

I have even tried specifying the exact path. Like this

	require('/hsphere/local/home/cphinney/blog.liquidarchaeology.com/wp-blog-header.php'); 

 

When that line is in /hsphere/local/home/cphinney/liquidarchaeology.com/default.php it works.

When its in /hsphere/local/home/cphinney/liquidarchaeology.com/team/team.php it doesnt.

 

The only diff is that one is in the root of the website and the other is in a folder under that same root.

<?php
/**
* Loads the WordPress environment and template.
*
* @package WordPress
*/

if ( !isset($wp_did_header) ) {

$wp_did_header = true;

require_once( dirname(__FILE__) . '/wp-load.php' );

wp();

require_once( ABSPATH . WPINC . '/template-loader.php' );

}

?>

 

Stock. And working on pages in the root of my site. Just not in subfolders.

So, how do you know it is not working?

 

The problem may be that the script is working, but when it tries to parse the includes within the script, they fail.

 

Temporarily change your script to :

if ( !isset($wp_did_header)) {
echo 'Header defined.';
} else {
echo 'Header not defined.';
}

 

My point is that it is likely that the problem exists with your included script. To further prove this, change that script to simply ECHO out the paths, instead of including them. Like :

 

echo dirname(__FILE__) . '/wp-load.php';

 

More then likely, these paths are not valid from beneath the root directory.

Ok so I was composing an email saying that "of course its not working... see for yourself" but decided that some people may be smarter than me  ::) and I tried it your way.... lol

 

I changed to the code you specified and I got "header defined" even on the page that wasn't working. So not wanting to break WP but wanting to get my non blog site working with these files what do you suggest.

So I smattered a few echos around the code and tracked down the following;

 

It dies at this line in taxonomy.php

$wp_taxonomies['category'] = (object) array('name' => 'category', 'object_type' => 'post', 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count');

 

Now I am not that PHP savy to know whats going on here or what the folder structure of my website could have to do with this. But an echo before and after this line only shows the echo before.

 

Suggestions apreciated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.