<html>
<head>
<title>Week #10 Example ~ Lestat</title>
<link rel="stylesheet" type="text/css" href="/css/scriptskewl.css">
</head>
<body>

<?
$file_directory 
'/home/content/h/o/t/hotestimator/html';
$error 'Sorry, I could not open this file! Check that the permissions are set properly 
             for this file and that you used the correct absolute path to the file.'
;
$file_contents file("$file_directory/.htpasswd");
sort($file_contents);
$sizeof count($file_contents);

// start action routine for actual deletion or additon of new members
if ($_POST['action'] == "add") {
    if(
$_POST['user'] != '' && $_POST['pwd'] != ''){
       if(
$filehandle fopen("$file_directory/.htpasswd""a")) {
            
$encrypted_pass crypt($_POST['pwd']);
            
fputs($filehandle"$user:$encrypted_pass\n");
            
fclose($filehandle);
            print(
"Successfully added <b>$user</b> to the file");
       } else {
        echo(
$error);
      }
    }else{
        print(
"Nothing was added");
    }
}

// [ DELETE ]
if ($_POST['action'] == "delete") {
    if(
$todelete != ''){
          if(
$filehandle fopen("$file_directory/.htpasswd""w")) {
                for(
$i=0$i $sizeof$i++) {
                   if(
$file_contents[$i] != $todelete) {
                      
fputs($filehandle"$file_contents[$i]");
                   } else { 
$flag 1; }
                }
                
fclose($filehandle);
                if(
$flag) { print("Successfully deleted <b>$todelete</b> from the file");
                } else {
                    print(
"I didn't find $todelete to delete from file");
                }
          } else { 
            echo(
$error);
          }
    }else{
        print(
"Nothing to Delete");
    }
}
?>
    <form method=POST action="<? echo($PHP_SELF); ?>">
    <input type="hidden" name="action" value="delete">
    <select name="todelete">
    <?
    $file_contents 
file("$file_directory/.htpasswd");
    
sort($file_contents);
    
$sizeof count($file_contents);
    for(
$i=0$i $sizeof$i++) {
       
$user explode(":"$file_contents[$i]);
       print(
"<option value=\"$file_contents[$i]\">$user[0]</option>");
    }
    
?>
    </select> <input type="submit" value="Delete User">
    </form><br>
    
    <form method=POST action="<? echo($PHP_SELF); ?>">
    <input type="hidden" name="action" value="add">
    Username: <input type="text" name="user" size=10><br>
    Password: <input type="password" name="pwd" size=10> <input type="submit" value="Add New User">
    </form>
    
<br>
See if your <a href="folder/page1.html">username/password</a> works !











<pre>



</pre>


<a href='../index.html'>Index</a>

<br>
<iframe src='examplesrc.php' width='100%' height='300'></iframe>
<br>

<a href='../index.html'>Index</a>

</body>
</html>