php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20452 Problems requiring/including when original file is a symlink
Submitted: 2002-11-15 17:35 UTC Modified: 2002-11-17 23:08 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: pupeno at pupeno dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.2.3 OS: Linux Mandrake 9.0
Private report: No CVE-ID: None
 [2002-11-15 17:35 UTC] pupeno at pupeno dot com
I'm requesting a page, the file that is called is   
index.php, but this file is a symlink from somewhere else.   
When I require a file from index.php, if there's no '..' 
(dots) on  the path (a relative path, but not going back), 
the relative path is from where  the original file is, but 
if there are  '..' on the path, the relative path is   
from where the symlink is (although php identifies the 
script as the original file in the error message).  
   

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-16 11:48 UTC] iliaa@php.net
Could you show an example of what you mean?
 [2002-11-17 00:17 UTC] pupeno at pupeno dot com
I don't have a 'working' on line example to show you this and I 
don't have posibilities to do it right now, I'm sorry, but I'll try to 
show you here what I mean with an example. 
Let's supouse I have one script in this file 
/var/php/scripts/index.php 
and I have a symlink to that file like this 
/var/www/htdocs/index.php -> ../../php/scripts/index.php 
and this file contains the following: 
<?php 
	require("dir/include.php"); 
	require("../dir/include.php"); 
?> 
When I run it, for require("dir/include.php"); it tryes to include 
/var/php/scripts/dir/include.php (the relative path from the 
original location of the file) but for require("../dir/include.php"); it 
tryes to icnlude /var/www/dir/include.php (real path for 
/var/www/htdocs/../dir/include.php) (it is resolving the relative 
path from the symlink and not the original file). 
I'm not sure with behaviour is the right one, but this mix is not 
the right one for sure, I think. 
I hope it helps, if you need more help, just contact me. 
Thank you.
 [2002-11-17 18:06 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

When including a file, it is included based on the directory you are currently in. If that directory was /var/php/scripts/ , then all relative paths will be calculated based on that directory.
 [2002-11-17 23:08 UTC] pupeno at pupeno dot com
I think you don't understand me. 
In which directory are you in when executing a script ? 
The directory where the symlink is or the directory where the 
original file is ? 
Well, depending if the path goes backwards or not (with two 
dots '..') the path to calculate a relative path is one or the other. 
Do you understand me ? 
require("dir/include.php"); loads /var/php/scripts/dir/include.php 
while require("../dir/include.php"); loads /var/www/dir/include.php. 
They're calculated from diferet base paths, please, take a look at 
the example I gave, exactly at the paths, there is where the 
problem is. One path is calculated from where the file is, and the 
other path is calculated from where the symlink is, and the only 
diference between both paths is the '..'. To give you a better 
example. 
Original script: /var/php/scripts/index.php 
Symlink: /var/www/htdocs/index.php -> ../../php/scripts/index.php 
Acording to what you say (which makes sense to me) this two 
lines should include the same file: 
require("include.php"); 
require("../scripts/include.php"); 
right ? 
well, the first one fill succesfully include 
/var/php/scripts/include.php 
while the second one will include 
/var/www/scripts/include.php (because this path instead of 
being /var/php/scripts/../scripts/include.php is 
/var/www/htdocs/../scripts/include.php) It is resolved from the 
location of the symlink and not the original file.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 17:01:33 2025 UTC