Comment 5 for bug 780237

Revision history for this message
Hugh Davenport (hugh-davenport) wrote :

Ok so the way moodle does it is work it out at install time and write to config.php (they require document root to be writeable...)

The way they get the wwwroot path is get the proto + hostname roughly the same way as mahara, then for the path above / they do the following:

get the path from one of the following (in order)
$_S['REQUEST_URI']
$_S['PHP_SELF']
$_S['SCRIPT_NAME']
$_S['URL']
The final three have '?'.$_S['QUERY_STRING'] appended if it is not empty

This string is then exploded around '/install.php' and voila, path to wwwroot.

The problem with doing this in mahara is that we don't know each time what should be exploded (ie what file is being run, as __FILE__ will always be init.php in the /true/ path (ie /home/hugh/src/mahara/mahara/htdocs/init.php in my case))

How I have done it is append each directory in PHP_SELF to DOCUMENT_ROOT, test it with realpath() against dirname(__FILE__), and stop when they are the same.

This should work no matter what script is actually being called, and only is a performance issue if the users have several directorys under document root (most will have none, then maybe a few with one, little with two or more most likely...)

https://reviews.mahara.org/140