pachanga1 Posted March 28, 2010 Share Posted March 28, 2010 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"); ?> Link to comment https://forums.phpfreaks.com/topic/196755-php-webform-user-change-password-field-in-csv-flat-file/ Share on other sites More sharing options...
trq Posted March 28, 2010 Share Posted March 28, 2010 the current script is: And your problem modifying it is? Link to comment https://forums.phpfreaks.com/topic/196755-php-webform-user-change-password-field-in-csv-flat-file/#findComment-1032940 Share on other sites More sharing options...
pachanga1 Posted March 29, 2010 Author Share Posted March 29, 2010 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! Link to comment https://forums.phpfreaks.com/topic/196755-php-webform-user-change-password-field-in-csv-flat-file/#findComment-1033360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.