Based off aoshiftctrl htaccess
..this is a .htaccess/htpasswd combo creation PHP class (with example). The previous script wasn't working and so this script aims to correct and extend the features to allow for full creation of htaccess/htpasswd/htgroup files.
-
Include htaccessible.class.php and create a new object.*
include("htaccessible.class.php"); $htaset = new htaccessible($hashtype,$options);
$hashtype is used to decide the encryption used for each password hash current values are: md5, sha1 or md5-digest.
TO DO: To set the blowfish encryption (need newer version of APache to do so)
-
Once this is set you need to configure these htaccessible variables to get it to work (full list of functions below):
$htaset->filelocation(<filepath for all files goes here>); $htaset->add_user(<string of username(s) go here (white-space seperated)>); $htaset->add_pwd(<string of password(s) go here (white-space seperated)>); $htaset->add_auths(<string type of authentication used>, <string name of directory>);`
-
After this initiate file creation (only once the above variables are complete otherwise it will not work correctly)
$htaset->htcreate();
-
add_auths(<string $authentication_type>,<string $directory_name>)
required functionSets
$this->authtype
and$this->authname
respectively. Both variables are required for the .htaccess file to render and work correctly.Please see these links for more info:
-
http://httpd.apache.org/docs/2.2/mod/core.html#authtype (Apache Docs AuthType Directive)
-
http://httpd.apache.org/docs/2.2/mod/core.html#authname (Apache Docs AuthName Directive)
(Digest authentication not yet added. Feature is planned - see Repo Milestones for est. time)
-
-
add_pwd(<string $password | string $passwords [white-space seperated]>)
required functionSets
$this->pwd
if string is single result else$this->grouppwds
if this string has multiple seperated [white-spaced] entries. Multiple entries are split into an array for later use.add_pwd
andadd_users
string results must match up otherwise htcreate() will throw an error
-
add_users(<string $username | string $usernames [white-space seperated]>)
required functionSets
$this->username
if string is single result else$this->groupusers
if this string has multiple seperated [white-spaced] entries. Multiple entries are split into an array for later use.add_pwd
andadd_users
string results must match up otherwise htcreate() will throw an error
-
create_file(<string $file>,<string $content>)
Creates file as long as it is a valid path.
-
delete(<string $filepath>)
Deletes file as long as it is a valid path. Use deletefiles() instead as delete() is a private function used in the deletefiles method
-
deletefiles(<string $filepath | array $filepaths>)
Detects whether files exist and proceeds to delete them.
-
edit(<string $filepath | string $edit | string $replace>)
Will edit already existing files with new content
Have not implemented any timeout/size limit functions for this (planned feature - 04/08/2013)
-
htcreate()
required functionCreates the .htaccess, .htgroup and htpasswd config using variables set.
Variables must be set before calling otherwise error will be thrown
-
setasarray(<string $variable [seperated-variables]>,<string $exploder [string delimiter]>)
Takes string with delimiter-spaced variables and creates array using explode. If $exploder isn't set then assumes delimiter is whitespace.
-
setarrayandcount(<string $variable [whitespaced-variables] || array $variables>)
Takes string or array and outputs number of array items as an integer. If string is given then it will be converted into an array then counted.