Jump to content

[SOLVED] Includes, Functions, and directory tree combination problems.


WilliamBrall

Recommended Posts

Hi, I'm in quite the pickle.

 

Nevermind where it is I work, but I'm building a rather complicated template system. One of the features of this system is that it can be placed off it it's own directory and included from elsewhere on the site. Right now I'm using a very crude system to do that:

$url_base = $_SERVER['HTTP_HOST'];
include("http://$url_base/THING.php");

 

That is the first important piece of information here.

 

Once, in this case, THING.php is called, thing will itself call additional template files using the same exact method.

 

One such file, lets call it PART.php, calls another called lets say FUNCTIONS.php. Functions has a big collection of plain ordinary average function definitions.

 

function heading($title, $description, $keywords, $doc_class, $urls, $media) // The heading of the page.
{
}

 

for example.

 

Finally, in PART.php those functions are used.

 

Here is the problem. Everything up until the functions are used will parse and display 100% correctly. Once any single function is called, the page breaks and stops processing entirely.

 

I narrowed the problem down to 'what' is causing it.. That is, in general. I have no idea what is causing it specifically. The combination of the fact that the template files are in a different directory than the base file, lets say INDEX.php, and the string used to call them. Nothing else is different between the working template all in one directory, and the split up template.

 

If nothing worked, I would say it isn't including them, but it most certainly is including them. It simply just won't handle the functions.

 

I haven't been able to locate any information on this, it isn't an easy thing to search for.

 

I'm not new to PHP, I've just never run across this problem before. Any ideas? Any help at all is welcome.

 

Thanks

 

Link to comment
Share on other sites

Not yet, I will, only because I can't think of anything else.

 

Can you think of a reason why getting the URL that way would make a difference? Wouldn't they end up with the same string? Wouldn't the include just fail, rather than work sans-functions, if it was wrong?

 

It's such a naughty bug, hides behind all the walls. :)

Link to comment
Share on other sites

i actually didn't know that you could include() a URL, but you can, so I'm not of much help on why it does or doesn't work properly. Perhaps it is a 'relative location' issues... dont' know.

 

anyway, if the file is on the same server, using a URL in the include() doesn't make sense to me anyway. we have sort of added another complexity onto the include. i think why not reference it directly via DOCUMENT_ROOT instead?

Link to comment
Share on other sites

The answer is pretty simple. The development server and live server has slightly different structures internally, but the same paths from a url standpoint. So I would have to change all the file-paths by hand later. Doing it this way makes so I just have to copy it over when it all works. Easy Peasy.

 

Thanks for trying, though. It is a really sticky problem. I can get PHP to spit out final fantasy style games, but this simple issue grinds me to a hault.

 

What do you think the chances are that the problem is a bug in PHP? To be honest, I am not privy to some details others take for granted. I don't have access to php.ini nor do I have the rights to make certain changes.

 

Are you aware of anything in php.ini that would let you turn functions off for included files that use URLs? Seems odd, considering the entire thing works if they aren't functions.

Link to comment
Share on other sites

So I would have to change all the file-paths by hand later.

 

write the code so that you only have to change it in one place. i do this all the time so that i just copy my code from my local dev environment to live and it works without changing anything. i have it auto-change using something like this:

 

if (stristr($_SERVER['DOCUMENT_ROOT'], "lesbrown")) { // Local server
define("DB_SERVER","localhost");
define("DB_USER","######");
define("DB_PASS","#####");
define("DB_NAME","#######");
$temp_doc_root = "/Users/lesbrown/Sites/site1/xyz.com/public_html/tiger/secure-area/admin/";
} else { // Live server
define("DB_SERVER","localhost");
define("DB_USER","#####");
define("DB_PASS","#####");
define("DB_NAME","#####");

$temp_doc_root = "/home/xyz/public_html/secure-area/admin/";
$preview_url = "http://www.xyz.com/secure-area/admin";
}

 

What do you think the chances are that the problem is a bug in PHP?

 

approaching zero.

 

Are you aware of anything in php.ini that would let you turn functions off for included files that use URLs? Seems odd, considering the entire thing works if they aren't functions.

 

no, but it seems like a nasty security issue to allow include(URL) and then allow use of functions inside.

Link to comment
Share on other sites

Thanks. I did solve the problem. It was my own stupidity clouding my judgment. I didn't think that PHP might pre-process my own site then send it to itself. Thats what it did.

 

It was sending back plain html, and because it wasn't getting to the construction of the page through the functions, I couldn't tell. That's also why it didn't toss any errors until it hit the then-undefined functions.

 

I may try to use your switcher idea BLueSkyIS, that's a really good idea. At leasts solves the most common replacements. Won't fix transporting to whole new systems. But that is rare.

 

Thanks a bunch guys

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.