View Full Version : Big help needed, please!

09-09-2005, 03:43 PM
Hi there.
I have a big question to ask, I've asked elsewhere but I am completely stumped and have been trying to resolve this for weeks now.

To introduce the question, our site currently has a login system which is based on sessions except a login date and time which is a cookie.

We allow users to change their passwords by a form which them proceeds to a pass.php which is based on the below. Our user data is stored in a flatfile (we don't use any sql db) which is in a protected directory and is laid out like: user,md5pass

The pass.php:


function output_error($text='')
echo "<p class=\"pagetitle1\">Alert...</p>\n<div class=\"messagebox\">\n<p>Alert:</p>\n<ul>\n" . $text . "\n</ul>\n</div>\n";

if ($newpass != $newpass2) {
output_error('<li><span>Your new and confirmed passwords do not match.</span></li>');
if ($_POST['nowpass'] == $_POST['newpass']) {
output_error('<li><span>Your old and new passwords appear to be the same. Please use this facility to change your password.</span></li>');
if (!isset($_SESSION['correctcode'])) {
output_error('<li><span>Please enable cookies.</span></li>');

$correctcode = $_SESSION['correctcode'];
$securitycode = $_POST['securitycode'];
if ($securitycode != $correctcode) {
output_error('<li><span>The human validation check failed, please try again.</span></li>');

$user = $_SESSION['account'];
$nowpass = md5($_POST['nowpass']);

$newpass = md5($_POST['newpass']);
$newpass2 = md5($_POST['newpass2']);

if( $nowpass == $_SESSION['password'] ) {

$filename = "/home/us/hidden/users.txt";
$file = file( $filename );
$newfile = '';

foreach($file as $val) {
$val = trim($val);
// There was space at the beginning and end of the line for me
// to see the space in action uncomment the next line
// var_dump($val);
if($val == "{$user},{$nowpass}") {
$newfile .= "{$user},{$newpass}\n";
} else {
$newfile .= "{$val}\n";

if(is_writable($filename)) {

if(!$fp = fopen( $filename, "w" )) {
output_error('<li><span>There was an error talking to the database. Please try again later.</span></li>');

if(fwrite( $fp, $newfile, strlen($newfile) ) === FALSE) {
output_error('<li><span>There was an error writing the database. Please try again later.</span></li>');

output_error('<li><span>Success! Your password has been successfully changed.</span></li>');

} else {
output_error('<li><span>The database seems to be non-writable. Please try again later.</span></li>');

} else {
output_error('<li><span>Sorry, your old password has been entered incorrectly.</span></li>');

Basically, what we want to achieve now is to create a new file, details.txt which will contain all the following stuff for each user:

First name(s)
Date of Birth
E-mail address
House no/name
Street name
Telephone no
Mobile no
Fax no

and echo out each value on a my.php.

My questions are:

1. In details.txt, how should I lay it out, just on one line for each user with commas between them?
2. How do I echo out the values on my.php?
3. I want to create an edit_details.php that can allow the users to edit their credentials based on the above pass.php

As mentioned, I've been trying this for weeks now with no luck so any advice would be MUCH appreciated.
Hope I have explained this okay.:)


09-09-2005, 04:45 PM
yah just put it all in one line, and use the LIST function: