Opened 14 years ago
Closed 9 years ago
#15838 closed defect (bug) (worksforme)
get_home_path() mixes PHP and server paths
Reported by: | reviewmylife | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.0.3 |
Component: | Filesystem API | Keywords: | has-patch |
Focuses: | Cc: |
Description
FYI: I've looked through the other get_home_path() tickets and believe this to be a different issue.
If the home and site urls are the same then you get a PHP relative path returned. i.e. it uses ABSPATH
, which is calculated using the PHP constant __FILE__
.
If the home and site urls are different you get a server relative path returned. i.e. one calculated via
$_SERVER["SCRIPT_FILENAME"]
.
With web hosts who have the server and PHP paths configured consistently this is no problem.
But on 1and1 it could be if you are comparing the return value of this function against another path. If the function can either return a PHP or a server path then your code may not always work.
The server path (Apache) on 1and1 has an extra '/kunden' at the start. This means that PHP and Apache retrieve paths slightly differently.
Example.
Blog with same home and site urls
get_home_path = /homepages/xx/dxxxxxxxx/htdocs/site1
Blog with different home and site urls
get_home_path = /kunden/homepages/xx/dxxxxxxxx/htdocs/site1
I'd suggest that as this is PHP the right thing to do is to always calculate the path using PHP relative paths - i.e. using
__FILE__
/ ABSPATH
. Don't use the server relative paths at all as you can't rely on them being the same as the PHP ones.
Certainly having a function returning a path that can be calculated from two different base paths is a bad idea.
For reference here's the current function:
function get_home_path() { $home = get_option( 'home' ); $siteurl = get_option( 'siteurl' ); if ( $home != '' && $home != $siteurl ) { $wp_path_rel_to_home = str_replace($home, '', $siteurl); /* $siteurl - $home */ $pos = strpos($_SERVER["SCRIPT_FILENAME"], $wp_path_rel_to_home); $home_path = substr($_SERVER["SCRIPT_FILENAME"], 0, $pos); $home_path = trailingslashit( $home_path ); } else { $home_path = ABSPATH; } return $home_path; }
Attachments (2)
Change History (7)
@
13 years ago
Accounting for differences between ABSPATH and $_SERVERDOCUMENT_ROOT? and caching return value
#2
@
13 years ago
- Cc kpayne@… added
- Keywords has-patch added
I was able to recreate this, partially, on 1and1 hosting. The $_SERVER['PHP_DOCUMENT_ROOT']
variable isn't present on my test account. The $_SERVER['DOCUMENT_ROOT']
and __FILE__
paths differed as reported by reviewmylife. The DOCUMENT_ROOT was prepended with /kunden
.
Patch 15838.patch should resolve the problem without affecting backwards functionality.
#3
follow-up:
↓ 4
@
13 years ago
- Keywords get_home_path 1and1 removed
Can we please get a var_export() of $_SERVER on an affected site?
(Var_export so we can dump it straight into a test environment)
A bit more background info is in this comment: http://wordpress.org/support/topic/plugin-wp-super-cache-how-to-get-mod_rewrite-working-on-1and1-shared-hosting?replies=8#post-1837843