500pts: Set includes path for cgi PHP without editing php.ini

Hello all,

I have PHP5 installed as a cgi.  And I have a website that is hosted in a sub-folder among many others within a hosting account.  This website is using PHP.

I want to set a constant includes folder pat so that I don't have to worry about the path as the site gains more and more levels.  BUT, because this is not the only site hosted in this hosting account (each in their own folders with domain pointers), I DON'T want to set the include path in the php.ini file, otherwise I have to put all includes for all sites in the same folder.

My understanding from reading is that include path can be set using htaccess only when php is installed as a module, not as a cgi.  

Is there some other way I can achieve what I want?

Thanks.
LVL 1
xfvgdrthbdtyvhgscvAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ChokeholdCommented:
What about using the:

<?php
// Works as of PHP 4.3.0
set_include_path('/inc');
?>

Sets the include_path configuration option for the duration of the script ..

0
ChokeholdCommented:
the above was just an example where inc is the path:

string set_include_path ( string new_include_path )

0
xfvgdrthbdtyvhgscvAuthor Commented:
Thanks for the idea.  

I need to be more clear: I don't want to have any reference to the path to the includes in the page's file.  If I have 200 html pages in my site scattered through three levels of sub-directories, I want to be able to just put

<?php include "my_include.txt" ?>

and have it go to one central include directory regardless of which level of sub-directory the page was in.

If I use the set_ini() function, I still have to incorporate that into each page file.

Basically, I want something that worls like an htaccess include path declaration - that is, "for every php file from here down, use xyz as the include folder path".
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

xfvgdrthbdtyvhgscvAuthor Commented:
Wait a minute - maybe I made a dumb reply.

set_ini() could work [b]IF[/b]

a) the path can be set NOT relative to the directory of the page running the script, but as an absolute path, perhaps from the account root ora url

b) the code will not show up in the source of the rendered page; that is, there is no way for users to ever see it.

Then I could paste the exact same code into the header of every page file.  It's not glorious - if I ever migrate the site to its own hosting account where it would be simpler to just edit php.ini, I'll have to go through each and every page file to remove that snippet.  But it might do in a pinch for now if it can work like that.
0
xfvgdrthbdtyvhgscvAuthor Commented:
Of course that's set_include_path(), not set_ini().
0
davebytesCommented:
Why even bother with trying to reset the include directory?  That actually introduces more potential issues.

Just use an absolute path.  I don't know, something like:

<?php include(_SERVER["DOCUMENT_ROOT"].'/inc/my_include.txt'); ?>

No matter what server you move to, so long as that server var is properly filled, and you put /inc directory in your public html root, you are good to go.

Nothing from the include statement should make it to the html.  do @include if you are concerned about a possible error making it to the user, the @ will eat it.

-d
0
xfvgdrthbdtyvhgscvAuthor Commented:
Also an interesting idea.

But now, if I ever want to change the location of my includes directory, I have to go back and edit every single web page file.

IDEA - can I set a programmer-defined variable in the php.ini file?  Can I define my own $perso_includes_path variable in the php.ini file, and then refer to it in php code, like

<?php include($perso_includes_path.'/inc/my_include.txt'); ?>

That way, if I move things around, I have only that one line to edit.
0
WhiteWings007Commented:
I would preferably make a variable like this

$include_path = "($_SERVER["DOCUMENT_ROOT"].'/inc";

in your main function file, or header file, atleast something that is called in every file.

then in your files you can only type

include_once("$include_path/my_include.txt");

this way if you wanna change the folder, you only need to do this one place.
hope this works for you :)
0
WhiteWings007Commented:
err, minor edit from my first post

$include_path = "$_SERVER["DOCUMENT_ROOT"].'/inc";
0
davebytesCommented:
"if I ever want to change the location of my includes directory"

just don't. ;)  but really, pick a location you can live with.  In the worst case, a script could be written to modify that line in all other scripts.  I don't know of anything you could pre-set in php.ini (though, if you could pre-set your php.ini, you could change your default include path, and this would all be moot!).

If you want to indirect it a little, you could do something like:

<?php include(_SERVER["DOCUMENT_ROOT"].'/root.inc'); ?>
<?php include($perso_includes_path.'/inc/my_include.txt'); ?>

where /root.inc sets $person_includes_path and nothing else.  THEN, in the worst case, you'd have to have a root.inc file even if you moved the location of /inc to somewhere else, but one file with one line might be worth it if you are unsure of a path.

-d
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
xfvgdrthbdtyvhgscvAuthor Commented:
Goahm I hate to be difficult, and myabe I'm missing something, but if I put

$include_path = "($_SERVER["DOCUMENT_ROOT"].'/inc";

in my "main function file, or header file, atleast something that is called in every file"

then i STILL have to include the path to that main function include, hardcoded into each web page file.  No?
0
xfvgdrthbdtyvhgscvAuthor Commented:
Davebytes is closest to the mark so far.  Creative idea, I like it.  I can see this root.inc file being an opportunity to set all kinds of site-wide variables.'

Along those lines, I found this:

http://www.hamweather.net/hw3/docs/hw3php/inifiles.html

"Template Loading INIs

Lastly, when HW3 is parsing through a template for outputting, the template can make HW3 load an INI file as well. If while outputting the template, if HW3 comes upon "%%CONFIG=xxx%%", then HW3 will attempt to load the xxx.ini.php file if it exists.

This is very useful to load a set of user defined variable presets. Thus at the beginning of your header you could load an INI file which held user defined variables which define the font faces, colors and other various settings"

But I'm not sure if this will work for me, or how what they refer to works.
0
WhiteWings007Commented:
unfortunatley yes, didnt think about it too much before i answered,
what i have been doing is that i include my function file in each file, and every other file that is included in my scripts uses that variable.
Pretty much just what davebytes said, and that kinda leaves you back to where you started
0
xfvgdrthbdtyvhgscvAuthor Commented:
Everyone sure I can't just define my own variable in the php.ini file and then refer to it?
0
WhiteWings007Commented:
I have never been altering my php.ini file, so i really cant help you with that, but look at:

http://www.washington.edu/computing/web/publishing/php-ini.html

too see if you can get some ideas
0
xfvgdrthbdtyvhgscvAuthor Commented:
OK, here's about as good as I can imagine using combinations of ideas, but especially davebytes'.

Instead of putting the this root.inv file at the document root, put it in the default includes directory.  That way, I don't have to clutter up the root with extraneous php files, AND the include statement for this file can be path-less, since php will look first in the default directory.  Then, in that file, re-set teh default includes path.

Lokks about as close as I'm going to get.
0
xfvgdrthbdtyvhgscvAuthor Commented:
Tried it - yep, that does it.  Now on my site I just have to include a one-liner set_ini() in the default includes directory, paste an include at the top of the html page template referencing this file with no path, and I can set the includes path for the whole site.  Not once do I have to hard code a path into any web page file.  And neither do I have to  clutter up the ftp space with extaneous files.  It;'s all contained where it was meant to be contained.

Thanks for the help everyone.
0
xfvgdrthbdtyvhgscvAuthor Commented:
So, I;ve split the points betwen Dave & Chokehold, since my final solution is a combinatino of their two ideas.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.