Jump to content

Including files help


ryan.od

Recommended Posts

OK, I have searched and searched for an answer to this problem and have never come up with a solution (although I've seen many posts and pages about it).

PLEASE, PLEASE, PLEASE HELP!!

1. I cannot use absolute paths as this needs to be a generic solution. As such, this is not an option.

2. I have tried to use ../ to move up a level, but I get the following error: open_basedir restriction in effect. I would change this setting on the server, but I understand this is a security no-no. Not an option.

3. I have tried using $_SERVER['DOCUMENT_ROOT'] to determine the root and concatenate the file location onto it, but again, I understand this is a bad approach (treated differently by Windows based and Linux based servers). Again, not an option.

4. I tried to use ./ as I read somewhere this goes to the root folder? Doesn't work for me. Not an option.

I am out of ideas and possibilities. I know this is not a difficult issue. Seems to me every CMS out there does this. How the heck do they do it?? Thanks to whoever has the magic answer!!

RyanOD
Link to comment
Share on other sites

I suggest you remove the open_basedir restriction, and do your own checks to ensure that the files you include are "ok".  Programming always involves a tradeoff between security and flexibility, and in this case you need a little more flexibility.

"./" goes to the current directory, not the root directory.  "/" is the root directory.

You can find your current directory with getcwd(), if that helps.
Link to comment
Share on other sites

Hmmm, well, I decided I should check and see if my problem might be with how I included the files rather than a problem with the server. So I created a file that I put in its own folder that was at the same level as several other folders. I then had to use include('../folder/file') to include a file out of a folder on the same level (hope that makes sense).

It worked fine.

As such, I think my problem might be with how I am including things. However, I have tried all of the following:

menu/menu.php
/menu/menu.php
../menu/men.php
./menu/menu.php (?)
menu.php
/menu.php
../menu.php

. . .and none of them work! Uggh!!

When you are including several files and some of those files include other files, where does your path reference from? Is it the initial file that starts the trail of includes or is it the file location where the include is actually written?

Also, is there a general rule for this type of including? i.e. embedded include statements = YOU FEEL SHAME!! ??

Thanks to all.

Ryan OD
Link to comment
Share on other sites

OK, problem solved (for now).

Thanks to all for your help.

For anyone who cares (or has a similar issue), the solution I settled on was to declare $root at the beginning of every main file (index, blog, products, etc.) that way, all the included files would have access to the pathway to the root directory. Then, each include became, include ("$root"."folder/file.php"); and all you have to do is change the $root from "" to ".." for all files that are one level down and so on and soforth. It might not be an elegant solution, but it does work.

I think this is what The Little Guy was recommending. I saw it somewhere else that escapes me now as well.

Thanks again to everyone.

Ryan OD
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.