Source for file HtAccess.php
Documentation is available at HtAccess.php
/* vim: set ts=4 sw=4: */
+-----------------------------------------------------------------------+
| Copyright (c) 2002-2006 Mika Tuupola |
| Redistribution and use in source and binary forms, with or without |
| modification, are permitted provided that the following conditions |
| o Redistributions of source code must retain the above copyright |
| notice, this list of conditions and the following disclaimer. |
| o Redistributions in binary form must reproduce the above copyright |
| notice, this list of conditions and the following disclaimer in the |
| documentation and/or other materials provided with the distribution.|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+-----------------------------------------------------------------------+
| Author: Mika Tuupola <tuupola@appelsiini.net> |
+-----------------------------------------------------------------------+
/* $Id: HtAccess.php,v 1.16 2006/12/07 09:27:38 tuupola Exp $ */
require_once 'PEAR.php' ;
* Class for manipulating .htaccess files
* A class which provided common methods to manipulate Apache / NCSA
* Example 1 (modifying existing file):
* $h = new File_HtAccess('.htaccess');
* $h->setRequire('valid-user');
* Example 2 (modifying existing file):
* $h = new File_HtAccess('.htaccess');
* $h->addRequire('newuser');
* Example 3 (creating a new file):
* $params['authname'] = 'Private';
* $params['authtype'] = 'Basic';
* $params['authuserfile'] = '/path/to/.htpasswd';
* $params['authgroupfile'] = '/path/to/.htgroup';
* $params['require'] = array('group', 'admins');
* $h = new File_HtAccess('/path/to/.htaccess', $params);
* @author Mika Tuupola <tuupola@appelsiini.net>
* @return object File_HtAccess
* Load the given .htaccess file
* @return mixed true on success, PEAR_Error on failure
while ($buffer = fgets($fd, 4096 )) {
$data = split(' ', $buffer, 2 );
} elseif (preg_match('/AuthUserFile/i', $data[0 ])) {
} elseif (preg_match('/AuthGroupFile/i', $data[0 ])) {
} elseif (preg_match('/AuthDigestFile/i', $data[0 ])) {
} elseif (preg_match('/AuthDigestGroupFile/i', $data[0 ])) {
$require = split(' ', $data[1 ]);
} elseif (trim($buffer)) {
$retval = PEAR ::raiseError ('Could not open ' . $this->getFile() .
foreach ($params as $key => $value) {
* Set the value of authname property
* Set the value of authtype propery
* Set the value of authuserfile propery
* Set the value of authgroupfile property
* Set the value of authdigestfile property
* Set the value of authdigestgroupfile property
* Set the value of require property
* Parameter can be given as an array or string. If given as a string
* the value will be exploded in to an array by using space as a
* Add a value to require property
* Delete a value from require property
* Set the value of additional property
* Additional property is used for all the extra things in .htaccess
* file which don't have specific accessor method for them.
* @param array $additional
* Add a value to additional property
* @param string $additional
* Set the value of file property
* Get the value of authname property
* Get the value of authtype property
* Get the value of authuserfile property
* Get the value of authgroupfile property
* Get the value of authdigestfile property
* Get the value of authdigestgroupfile property
* Get the value(s) of require property
* @param string $type whether to return an array or string
* @return mixed string or array, defaults to an array
* Get the value(s) of additional property
* @param string $type whether to return an array or string
* @return mixed string or array, defaults to an array
* Get the value of file property
* Save the .htaccess file
* @return mixed true on success, PEAR_Error on failure
$retval = PEAR ::raiseError ('Could not open ' . $this->getFile() .
* Returns the .htaccess File content
$retval .= 'Require ' . $this->getRequire('string') . "\n";
Documentation generated on Mon, 11 Mar 2019 14:49:14 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|