Jump to content

PHP Webform User change password field in csv flat file


pachanga1

Recommended Posts

Hello,

I need some programming help ...been working on this for over a month and can't get it to work...I have a signup form which allows a user to save their username,password, address, email, phone.... to a flat file (csv).  I was wondering if someone can help me to program a script that will allow the user to change any of his information...reset a password, change phone...etc...your help is greatly appreciated! This has to be done using a flat file..thx!

 

the current script is:

 

<?php

 

session_start();

// functions

$ufilename = "userfile.txt";

//$email = $_POST['email'];

//$address = $_POST['address'];

$phone = $_POST['phone'];

$favcolor = $_POST['favcolor'];

$_SESSION["sname"] = $uid;

$_SESSION["semail"] = $email;

$_SESSION["saddress"] = $address;

$_SESSION["sphone"] = $phone;

$_SESSION["sfavcolor"] = $favcolor;

 

 

 

function saveCookie($username) {

    $cname = "userdata";

    $cvalue = $username;

    $exp = time()+60*60*24*30*12;      // one year

    setcookie($cname,$cvalue,$exp);     

}

 

function validateUser($userid, $pwd) {

    // does file exist?

    $retval = -1;

    // return values are -1 no user/pass

    // 0 means good user but bad pass

    // 1 means both ok

    global $ufilename;

 

    if( file_exists($ufilename)) {

 

        $filerecs = split("\n",file_get_contents($ufilename));

        $userpwd = crypt($userid,$pwd);

        // print "Userpwd is $userpwd";

       

        foreach ($filerecs as $line ) {

            // print "Line is $line";

            $recs = explode(",",$line);

           

            if( $recs[0]==$userid) {

                $retval = 0;

                if( $recs[1]==$userpwd) {

                    $retval = 1;

                }

                break;

            }

        }

        return $retval;

}

else {

    die("Read error");

}

}

 

function findUser($uid) {

    global $ufilename;

    if( file_exists($ufilename)) {

        $filerecs = split("\n",file_get_contents($ufilename));

        foreach ($filerecs as $line ) {

            // print "Line is $line";

            $recs = explode(",",$line);

            if( $recs[0]==$uid) return TRUE;

        }

        return FALSE;

    }

    else return FALSE;

}

 

function createUser($uid, $pwd, $email, $address, $phone, $favcolor) {

    // open file for append

    global $ufilename;

   

    $fp = fopen($ufilename,"a");

    $userstring = $uid.",".crypt($uid,$pwd)."," .$email."," .$address."," .$phone.",".$favcolor."\n";

    fwrite($fp,$userstring);

    fclose($fp);

}

 

///////////////////////////////////////////////////

 

if( $_POST['newuser']==TRUE) {

    if( findUser($_POST['uid'] )==FALSE ) {

        createUser( $_POST['uid'], $_POST['pwd'], $_POST['email'], $_POST['address'], $_POST['phone'], $_POST['favcolor']);

        header("Location: access.php");

    }

    else

        header("Location: resetpassword.html");

}

 

$valuser = validateUser( $_POST['uid'], $_POST['pwd']);

 

if( $valuser==1) {

 

    if( isset($_POST['usave']) && $_POST['usave']==TRUE ) {

            saveCookie( $_POST['uid'] );

    }

    include_once 'tokenpage.php';

    $_SESSION['token'] = $tokendata;

    header("Location: GetData.php");   

}

 

if( $valuser==0) header("Location: resetpassword.html");

 

// leave

if( $valuser==-1) header("Location: BadLogin.html");

 

 

?>

I don't know how to go about replacing the existing user data with new data...for example, if a user needs to replace their password or change their phone number...i've looked all over the web and can't find anything on it...any help is appreciated!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.