Hi there!
I've maid a multi-user-management script that stores some info (username, encr.password, latest login and so on...)
in a flat file (auth2.txt).
Since I wanted to print out the latest login of a user and be able print out if this user was online, on login the script stores the date in the texfile and changes the login to "1".
On log out it changes the login to "0".
All of this is working just fine, my problem is that if the number of users should increase my method of changing this vars in the file would be way to slow... Is there a smarter/faster way to updated the files than this (MySQL is not an option):
[LOGIN > AUTHORIZED]
$openr = fopen("auth2.txt", "r");
$openw = fopen("auth2temp.txt", "w");
$buffer = fread($openr, 4096);
$nuserstr = $auth[$uid];
$nuserstr[2] = $logdate;
$nuserstr[3] = 1;
$nuserstr = implode(":", $nuserstr);
$userstr = implode(":", $auth[$uid]);
$buffer = str_replace($userstr, $nuserstr, $buffer);
fwrite($openw, $buffer);
fclose($openr);
fclose($openw);
unlink("auth2.txt");
rename("auth2temp.txt", "auth2.txt");
if(file_exists("auth2temp.txt")) { unlink("auth2temp.txt"); }
[LOGOUT]
$openr = fopen("auth2.txt", "r");
$openw = fopen("auth2temp.txt", "w");
$buffer = fread($openr, 4096);
$nuserstr = $auth[$uid];
$nuserstr[3] = 0;
$nuserstr = implode(":", $nuserstr);
$userstr = implode(":", $auth[$uid]);
$buffer = str_replace($userstr, $nuserstr, $buffer);
fwrite($openw, $buffer);
fclose($openr);
fclose($openw);
unlink("auth2.txt");
rename("auth2temp.txt", "auth2.txt");
if(file_exists("auth2temp.txt")) { unlink("auth2temp.txt"); }
session_destroy();
[REMOVE USER]
$userstr = $auth[$del][0];
$userstr .= ":";
$userstr .= $auth[$del][1];
$userstr .= ":";
$userstr .= $auth[$del][2];
$userstr .= ":";
$userstr .= $auth[$del][3];
$userstr .= "\r\n";
$openr = fopen("auth2.txt", "r");
$openw = fopen("auth2temp.txt", "w");
$buffer = fread($openr, 4096);
$buffer = str_replace($userstr, "", $buffer);
fwrite($openw, $buffer);
fclose($openr);
fclose($openw);
unlink("auth2.txt");
rename("auth2temp.txt", "auth2.txt");
if(file_exists("auth2temp.txt")) { unlink("auth2temp.txt"); }
Thanks!
Vasse