First off I hope this is possible. My php script seems to be writing to the htpasswd file in the directory I want to protect.
First here is the htaccess file
AuthUserFile /home/******/AuthName "Members Only"
AuthType Basic
require valid-user
I made a blank htpasswd file and put it in the same directory chmoding it 777
Then inserted the following PHP script into the page I want people to sign up on.
<?php
if ($submit) //if the form has been submitted
{
if (!$nick || !$email || !$password || !$password2)
//if any of the fields were not filled in
{
$error = "All fields are required. Check input and try again"; //set error
} else {
if ($password != $password2) //if the passwords do not match
{
$error = "Passwords do not match."; //set error
} else //if everything went smoothly
{ //process form
$fp = fopen("/home/******/ "a");
//open file, chage this to the path
//to your .htpasswd. The a says to
//"append" to the end of the file.
fwrite($fp, "$nick:" . crypt($password) );
//write to the htpasswd file
fclose($fp);
?>
Information successfully entered. You are now registered.
<?php
}
}
}
if (!$submit || $error)
//if the form has NOT been submitted or if there is an error
{
//display form
?>
<br>
<?php if ($error){ printf("<font color=FF0000>%s</font>", $error); } ?> <!--
//if there is an error print it -->
<form method="post" action="<?php echo $PHP_SELF?>">
<table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Nick</td>
<td><input type="Text" name="nick" maxlength="25" width="25"
<?php if ($nick){ printf("value=%s", $nick);}?>></td>
</tr>
<td>E-mail</td>
<td><input type="Text" name="email" maxlength="50" width="25"
<?php if ($email){ printf("value=%s", $email);}?>></td>
</tr>
<td>Password</td>
<td><input type="Password" name="password" maxlength="25" width="25"></td>
</tr>
<td>Password Again</td>
<td><input type="Password" name="password2" maxlength="25" width="25"></td>
</tr>
</table>
<br>
<input type="submit" name="submit" value="Join">
</form>
<?php
} //end if statement
?>
I still cannot use the newly entered password and username to access the protected directory, does anyone have any suggestions?
First here is the htaccess file
AuthUserFile /home/******/AuthName "Members Only"
AuthType Basic
require valid-user
I made a blank htpasswd file and put it in the same directory chmoding it 777
Then inserted the following PHP script into the page I want people to sign up on.
<?php
if ($submit) //if the form has been submitted
{
if (!$nick || !$email || !$password || !$password2)
//if any of the fields were not filled in
{
$error = "All fields are required. Check input and try again"; //set error
} else {
if ($password != $password2) //if the passwords do not match
{
$error = "Passwords do not match."; //set error
} else //if everything went smoothly
{ //process form
$fp = fopen("/home/******/ "a");
//open file, chage this to the path
//to your .htpasswd. The a says to
//"append" to the end of the file.
fwrite($fp, "$nick:" . crypt($password) );
//write to the htpasswd file
fclose($fp);
?>
Information successfully entered. You are now registered.
<?php
}
}
}
if (!$submit || $error)
//if the form has NOT been submitted or if there is an error
{
//display form
?>
<br>
<?php if ($error){ printf("<font color=FF0000>%s</font>", $error); } ?> <!--
//if there is an error print it -->
<form method="post" action="<?php echo $PHP_SELF?>">
<table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Nick</td>
<td><input type="Text" name="nick" maxlength="25" width="25"
<?php if ($nick){ printf("value=%s", $nick);}?>></td>
</tr>
<td>E-mail</td>
<td><input type="Text" name="email" maxlength="50" width="25"
<?php if ($email){ printf("value=%s", $email);}?>></td>
</tr>
<td>Password</td>
<td><input type="Password" name="password" maxlength="25" width="25"></td>
</tr>
<td>Password Again</td>
<td><input type="Password" name="password2" maxlength="25" width="25"></td>
</tr>
</table>
<br>
<input type="submit" name="submit" value="Join">
</form>
<?php
} //end if statement
?>
I still cannot use the newly entered password and username to access the protected directory, does anyone have any suggestions?