php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28338 CGI include/require (realpath) mishandles relative paths
Submitted: 2004-05-09 19:57 UTC Modified: 2004-05-09 21:03 UTC
From: mzajonc at pomona dot edu Assigned:
Status: Not a bug Package: CGI/CLI related
PHP Version: 5.0.0RC2 OS: Linux Redhat 7.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
10 - 7 = ?
Subscribe to this entry?

 
 [2004-05-09 19:57 UTC] mzajonc at pomona dot edu
Description:
------------
It appears that when running php from the command line relative paths such as require("../include/test.php") do not function the same in php4.2.3 and php5.0.0RC2.  Relative paths in php5 are computed relative to the current directory not relative to the script.

This causes commands (typically run in crontab) like php -f /www/foo/bar/test.php to break if test.php has require/include statements that are relative.

Reproduce code:
---------------
The test script (located: /www/www.test.com/test/test.php):

<?php
echo realpath("../test/test.php")
?>

From command line:
$ cd /www
$ php -f /www/www.test.com/test/test.php


Expected result:
----------------
/www/www.test.com/test/test.php


Actual result:
--------------
When php4 is used, the output is as expected.

When php5 is used, realpath fails and returns FALSE.  It appears to consider realpath("../test/test.php") to be "/test/test.php" (given current directory of /www).  However, if you do "cd /www/www.test.com/test" and then run the same command, the realpath returns what is expected (since script location is the same as the current directory).


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-09 20:24 UTC] wez@php.net
This is expected behaviour with the CLI version of PHP.
 [2004-05-09 21:03 UTC] mzajonc at pomona dot edu
My bad.  I was comparing CGI with CLI.  I was previously using the CGI php4 as command line tool.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 02:01:33 2024 UTC