Why not use standard apache authentication?
Heres some sample code that may help:
for recreating the .htpasswd file when a new member signs up
Code:
// get all users data from the database
$result = mysql_query("SELECT * FROM users", $db);
// declare an array
$htpasswd = array();
// scroll thru all users data and add required user/pass to array
while($row = mysql_fetch_array($meresult)){
array_push($htpasswd, "$row[login]:" . crypt($row[password], 'AW'));
}
// make a backup of the previous password file if wanted
copy('members/.htpasswd', 'my_backup_dir/htpasswd.bak.' . time());
// Open and get a lock on the passwordfile
$fp = fopen('members/.htpasswd', 'a');
while(!flock($fp, LOCK_EX)){
sleep(1);
}
// rewrite the file
fseek($fp, 0);
ftruncate($fp, 0);
foreach($htpasswd as $var){
fputs($fp, "$var\n");
}
// complete the process
fflush($fp);
flock($fp, LOCK_UN);
fclose($fp);
in your members area php scripts you use the below to get the username of this user from apache:
Code:
$username = $_SERVER[PHP_AUTH_USER];
you can then get any of their details from mysql by doing a
Code:
SELECT * FROM users WHERE username='$username'
Thats about as secure as it gets really.