Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Big help needed, please!

    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:

    PHP Code:
    <?php
    session_start
    ();

    function 
    output_error($text='')
    {
        require_once(
    '/home/us/account/protect.php');
        include_once(
    '/home/us/account/header.php');
          echo 
    "<p class=\"pagetitle1\">Alert...</p>\n<div class=\"messagebox\">\n<p>Alert:</p>\n<ul>\n" $text "\n</ul>\n</div>\n";
        include_once(
    '/home/us/footer.php');
        exit();
    }

    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$newfilestrlen($newfile) ) === FALSE) {
                
    output_error('<li><span>There was an error writing the database.  Please try again later.</span></li>');
            }

            
    fclose($fp);
            
    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:

    Code:
    Rank
    Title
    First name(s)
    Surname
    Date of Birth
    E-mail address
    House no/name
    Street name
    Town
    County
    Country
    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.

    Regards,

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    yah just put it all in one line, and use the LIST function:

    http://php.ru.ac.za/manual/en/function.list.php


    -Ken


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •