I would recommend you to use a single file for each user, or at least a row in the file for each user.
Here's some code on how to have a single file for each:
## The format of the user file - save as $username.txt ##
## Da auth file - do not edit! ##
|u|username|/u|
|s|password|/s|
|r|userlevel|/r|
|t|regtime|/t|
|a|firstname lastname|/a|
|b|email|/b|
|c|postadress^zip^city|/c|
|d|company|/d|
|e|phone^mobile|/e|
## Da auth file - do not edit! ##
## Function for opening textfile and load it to string ##
function file_get_contents($filename, $use_include_path = 0) {
$fd = fopen ($filename, "rb", $use_include_path);
$contents = fread($fd, filesize($filename));
fclose($fd);
return $contents;
}
## Find specific user field from user file ##
function find_ufield($ustream, $startcode, $endcode) {
$uEnd = explode($endcode, $ustream);
$uStart = explode($startcode, $uEnd[0]);
$fvalue = $uStart[1];
return $fvalue;
}
## To open the dir with user files ##
if ($dir = @opendir("the_directory_with_user_files")) {
$users=array();
$count=0;
while (($file = readdir($dir)) !== false) {
if (substr($file,-4) == ".txt"){
$users[$count] = $file;
$count++;
}
}
}
closedir($dir);
$danum = count ($users);
sort($users);
reset($users);
## Loop through the files and pilfer out the user data ##
for ($f=0;$f<=sizeof($users)-1;$f++){
$fname = $users[$f];
$ustream = file_get_contents("the_directory_with_user_files/$fname");
$printuname = find_ufield($ustream, "|u|", "|/u|");
$printlevel = find_ufield($ustream, "|r|", "|/r|");
$regtime = find_ufield($ustream, "|t|", "|/t|");
$regtime = $datetime = date("d.m - Y", $regtime);
$printfullnames = find_ufield($ustream, "|a|", "|/a|");
$printfullnames = explode("^", $printfullnames);
$printfullname = $printfullnames[0]." ". $printfullnames[1];
$printemail = find_ufield($ustream, "|b|", "|/b|");
$printadress = find_ufield($ustream, "|c|", "|/c|");
$printadress = explode("^", $printadress);
$postadr = $printadress[0];
$zip = $printadress[1];
$city = $printadress[2];
$printcompany = find_ufield($ustream, "|d|", "|/d|");
$printphones = find_ufield($ustream, "|e|", "|/e|");
$printphones = explode("^", $printphones);
$phone = $printphones[0];
$mobile = $printphones[1];
if($mobile != "") $mobile = "/ $mobile";else $mobile = "";
## Here you may want to echo something ;-) ##
## Creation of new user - you'll have to edit the values/fields to fit your needs ##
$rtime = time();
$default_userlevel = "Rookie";
## Create file-string ##
$string_to_file = "## Da auth file - do not edit! ##\n|u|$username|/u|\n|s|$password|/s|\n|r|$default_userlevel|/r|\n|t|$rtime|/t|\n|a|$firstname $lastname|/a|\n|b|$email|/b|\n|c|$postadress^$zip^$city|/c|\n|d|$company|/d|\n|e|$phone^$mobile|/e|\n## Da auth file - do not edit! ##";
if (!file_exists("the_directory_with_user_files/$username.txt")) {
touch("the_directory_with_user_files/$username.txt"); // Create blank file
chmod("the_directory_with_user_files/$username.txt",0777);
}
$a = fopen("the_directory_with_user_files/$username.txt", "w");
fputs($a, $string_to_file);
fclose($a);
## To edit user data, you just pick all data for the user by reading his file, then create a new filestring from the updated values, and repeat the above ##
Just a suggestion, and you'll probably need to rewrite it a whole lot 😃
knutm