[wp-trac] [WordPress Trac] #15838: get_home_path() mixes PHP and server paths

WordPress Trac wp-trac at lists.automattic.com
Wed Dec 15 23:40:28 UTC 2010


#15838: get_home_path() mixes PHP and server paths
--------------------------+----------------------------------
 Reporter:  reviewmylife  |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  3.0.3
 Severity:  normal        |   Keywords:  get_home_path, 1and1
--------------------------+----------------------------------
 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;
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15838>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list