For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > July 2006 > help with php.ini include_path?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author help with php.ini include_path?
bobmct

2006-07-27, 7:57 am

I'm attempting to integrate some PayPalPro supplied modules which come with
their own directory structure. I've installed this "directory" into my
common "working" includes directory.

However, because the supplied code uses so many levels of includes PHP is
not finding the referenced included functions.

Heres an example:

my own working includes:

/cgi-bin/includes

and I've installed the PayPalPro supplied stuff into that directory which
then constructs:

/cgi-bin/includes/PayPal/
/cgi-bin/includes/PayPal/Stuff/
/cgi-bin/includes/PayPal/Stuff/more_stuff/
/cgi-bin/includes/PayPal/Stuff/more_stuff/etc/

and so on.

When I use "include_once("module_name.php"); in my program the compiler
FINDS the module but the module itself then includes more items from
further on down the tree.

I've added the recursed directories to my php.ini include_paths directive
but is this really necessary?

Does one have to include each and every directory explicitly or is there a
method to define "recurse from this directory down" somewhere? I've
searched the docs (books, bibles, groups, php.net, etc) and cannot seem to
come up with any other way.

Please tell me I'm crazy and that there is a more reasonable way to
accomplish this?

Advice, help appreciated!

Bob



Colin McKinnon

2006-07-27, 6:57 pm

bobmct wrote:

> I'm attempting to integrate some PayPalPro supplied modules which come
> with
> their own directory structure. I've installed this "directory" into my
> common "working" includes directory.
>

<snip>
>
> /cgi-bin/includes/PayPal/
> /cgi-bin/includes/PayPal/Stuff/
> /cgi-bin/includes/PayPal/Stuff/more_stuff/
> /cgi-bin/includes/PayPal/Stuff/more_stuff/etc/
>
> and so on.
>


The first thing to note is that, if possible you shouldn't put include files
within the document root. But lets assume you don't have a choice.

So your include path has
/cgi-bin/includes

So if we assume there are some files as follows:

/cgi-bin/includes/PayPal/pp.inc
/cgi-bin/includes/PayPal/Stuff/cc.inc

then you can certainly write your script as:

<?php
include("PayPal/pp.inc");

However as you may have noticed, this won't work too well if pp.inc
contains:
include("stuff/cc.inc");

(side note if pp.inc contains 'include("cc.inc");' then walk away carefully
deleting all files as you go).

Simplest solution is to move all the files up a dir:

cd Paypal
mv * ..

One other solution is to add /cgi-bin/includes/PayPal to your include path.

Another way is to rewrite the files to use relative addressing, e.g. in
pp.inc:

$mydir=dirname(__FILE__);
$include_file=$mydir . "/stuff/pp.inc";
include($include_file);

HTH

C.
bobmct

2006-07-28, 6:57 pm

Colin McKinnon wrote:

> bobmct wrote:
>
> <snip>
>
> The first thing to note is that, if possible you shouldn't put include
> files within the document root. But lets assume you don't have a choice.
>
> So your include path has
> /cgi-bin/includes
>
> So if we assume there are some files as follows:
>
> /cgi-bin/includes/PayPal/pp.inc
> /cgi-bin/includes/PayPal/Stuff/cc.inc
>
> then you can certainly write your script as:
>
> <?php
> include("PayPal/pp.inc");
>
> However as you may have noticed, this won't work too well if pp.inc
> contains:
> include("stuff/cc.inc");
>
> (side note if pp.inc contains 'include("cc.inc");' then walk away
> carefully deleting all files as you go).
>
> Simplest solution is to move all the files up a dir:
>
> cd Paypal
> mv * ..
>
> One other solution is to add /cgi-bin/includes/PayPal to your include
> path.
>
> Another way is to rewrite the files to use relative addressing, e.g. in
> pp.inc:
>
> $mydir=dirname(__FILE__);
> $include_file=$mydir . "/stuff/pp.inc";
> include($include_file);
>
> HTH
>
> C.


C,

Thanks for the short explanation. The PayPal directory structure is exactly
WHAT is supplied in the PayPal SDK and a look through their modules seems
to indicate that the structure must be maintained although their top level
"paypal" can be relative.

I was HOPING that php includes would be recursive but it appears not. What
I actually had to do was build my php.ini's include_path to include each
and every directory in the PayPal structure, each with a fully qualified
patch (what a real pain). Creates for a very long path.

There's GOT to be a better and/or another way.

Thanks,

Bob
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com