0

I have 2 root directories for a site, httpdocs and httpsdocs. I am sure its obvious what the 2 are for. But I want to keep things consistent through-out the site like global navigation. Right now I have two separate files for this (one in each side) and I would like to only have one. This is hard to maintain because each time I change one I have to change the other (if I remember to), it breaks the DRY rule. But if I try to include a file from one side to the other using a relative path it tells me the file path is not allowed because it goes outside the document root. If I try to include it with an absolute URL I get another error saying file access is disabled in the server configuration. (I am on a hosting account so the most I can change as far as server config is limited to .htaccess). So can anyone think of a work-around for this?

2 Answers 2

1

Why not put your global include file in yet another directory (lets call it library) and then have each http root have an include file that includes ../library/lib.php, then sets specific paramaters. This gives you the added benifit of your library php files not being in the document root path as well.

And actually. Updating because I just read the entry about "relative path" issues.

Could you set the "include path" php value to include that directory?

Something like this:

ini_set('include_path', realpath(dirname(__FILE__)."/../library").":".ini_get('include_path'));
require_once('lib.php');

Did a little more research - seems that changing open_basedir is not possible unless you are able to edit the httpd.conf or php.ini values. PHP Manual: open_basedir

Sign up to request clarification or add additional context in comments.

9 Comments

If they are not in the document root I cannot access them, I get an error telling me the path is not allowed every time I try. Is there a way to ALLOW this using .htaccess or something?
I get this error when I try what you said: Warning: main(): open_basedir restriction in effect. File(/var/www/vhosts/mydomain.com/library/lib.php) is not within the allowed path(s): (/var/www/vhosts/mydomain.com/httpsdocs:/tmp) :(
Sounds to me like you need to complain to your hosting provider that /var/www/vhosts/mydomain.com should be your "allowed path" not just httpsdocs or httpdocs. You may be able to override it with php_value open_basedir "/var/www/vhosts/mydomain.com:/tmp" in your .htaccess - if that doesn't fix your problem - complain to your host
@gnarf, thanks what exactly should I put in my .htaccess file? this line exactly: [php_value open_basedir "/var/www/vhosts/mydomain.com:/tmp"]? Thanks a lot for your help!
I would hope that would work (updated the answer to include that option as well) - but if not - its just bad configuration of the hosting provider. Its foolish to put "library" files in your document root anyway.
|
1

Do you have the ability to create symbolic links between the two directories?

3 Comments

I am not sure, my hosting is LAMP, how would I go about creating one? Thanks.
I don't think I can, I looked it up and I guess I need terminal access to the server but I do not, I can ask my service provider to set it up, is it possible to make a symbolic link to a directory then any file I want to share put in that directory? Thanks
I also tried to create one using PHP's symlink() and I get an error saying: "Permission denied". Very frustrating.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.