EDIT Sorry, misread the code.
The reason it won't work is because it keeps overwriting the file.
Put the fwrite outside of the loop, and concat the data in the $content var, like so:
PHP Code:
for($i=0; $i<count($names) || $i<count($passwords);$i++){
//echo ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode).'<br>';
$content .= ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode).'<br>';
}
echo $content;
$file = fopen("/home/psmith83/public_html/test/test.htpasswd", "w");
fwrite($file, '' . $content . '');
fclose($file);
This way it does it all at once. I asume you know what the concat ('.') does, but incase you don't:
PHP Code:
$var = 1;
$var=2;
echo $var;//outputs 2
$var .= 1; //concat 1-- makes value 21
echo $var; //outputs 21
As far as the class, it wan't that great. I am a self taught programer too, as are many on DD as far as I know.
EDIT2: Note: you can also append the info in the file fopen('file','a') (a instead of w) but doing it after is better in this case--or so I think.
Bookmarks