Re: Question regarding include() and symlinks to directories

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



reply at the bottom ...

(Karl Pflästerer) wrote:
> Hi
> let's say we have the follwing directory structure:
> directory test, with to subdirectories: a and b; both have ssi
> subdirectory; a has also a subdirectory c with an index.php file in it
> and in b we habe a symbolic link to a/c.
> 
> On the shell it looks like this:
> ,----
> | /htdocs/test>ls -gG *
> | a:
> | total 8
> | drwxr-xr-x  2 4096 Jan  4 20:55 c
> | drwxr-xr-x  2 4096 Jan  4 20:51 ssi
> | 
> | b:
> | total 4
> | lrwxrwxrwx  1    6 Jan  4 20:53 c -> ../a/c
> | drwxr-xr-x  2 4096 Jan  4 20:53 ssi
> | ~/htdocs/test>cat a/ssi/a.inc
> | In directory a
> | 
> | ~/htdocs/test>cat b/ssi/a.inc
> | In directory b
> `----
> 
> As you see whe have an a.inc in each ssi. If we call now the index.php
> which does nothing more than to:
>       include('../ssi/a.inc')
> what would you expect to read if you called b/c/index.php? I expected to
> read 'In directory b' but I read 'In directory a'.
> 
> ,----
> | ~/htdocs/test>(cd a/c && php -f index.php )
> | In directory a
> | 
> | 
> | ~/htdocs/test>(cd b/c && php -f index.php )
> | In directory a
> `----
> 
> In my opinion include() should respect symlinks to directories and not
> dereference them before finding the file to include. Or am I wrong here?

I have tested using your exact description and get the result, you can
be fairly certain this is not something specific to your server/machine.

I would tend to agree with your premise - but the php devs may have
decided against this behaviour on purpose.

although I must also say it's a rather convoluted setup, then again you may
have a very good/neat reason for wanting to setup a directory akin to
your example.

because I was curious I tried the following, namely creating a subdir 'd'
in each of dirs 'a' and 'b' and creating the index.php in 'a/d/' a then symlinking
'a/d/index.php' to 'b/d/index.php' and then running the same tests using the 'd'
subdirs .... and guess what the correct [according to your expectation/opinion]
'ssi/a/inc' file was included

I would suggest maybe asking the internals@xxxxxxxxxxxx mailing list
as to whether they consider this a bug - and then file a bug report
if asked.

I might suggest also adding the following 2 lines to your test
index.php - which might provide a little more insight:

echo "the current working directory is ",getcwd(),"\n";
echo "I am the index file, my name is ",__FILE__,"\n";

additionally I changed the contents of your 'a.inc' files to the following:

<?php echo "I'm an included file, my name is ",__FILE__,"\n";

---------------
my conclusion:
no real answers, one possible way to workaround the problem,
possibly requires a little php-dev input.


> The PHP version is 5.1.6 (will soon be updated).
> 
> 
>    KP
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux