tbucknall Posted February 11, 2013 Share Posted February 11, 2013 (edited) Hi there! I am wondering if anyone can assist my on creating a simple php script for creating, modifying and deleting users with PHP ONLY. No MySQL. I am quite new to PHP. I need it to be so that only an administrtaor can make those changes and visitors only have a log in page and home page. So far i only have the register and login working. I want to know how i can set up so an adminstrator can modify the users. thanks. this is the register script: <?php echo "password1 ".$_POST['password']; echo "<br>"; echo "password2 ".$_POST['password2']; echo "<br><br>"; if (isset ($_POST['submit'])) { $problem = FALSE; if (empty ($_POST['username'])) { $problem = TRUE; print "Please enter a username!"; } if (empty ($_POST['password'])) { print "Please go back and enter a password" ; exit; } if (empty ($_POST['password2'])) { print "Please go back enter your password in each box."; exit; } if (($_POST['password'])!==($_POST['password2'])) { print "Your password entries did not match! Please go back and correct them."; exit; } $fp = fopen ( 'users.txt', 'rb' ); while ($line = fgetcsv($fp,100,",")) { echo $line[0]." ".$line[1]; echo "<br>"; if ( ($line[0] == $_POST['username']) ) { echo "<b>Sorry! That username is already being used. Please go back and select another name.</b>"; fclose ( $fp ); exit; } } $fp=fopen('users.txt', 'ab' ); //$data =($_POST['username']).crypt($_POST['password']); $data =($_POST['username']).",".($_POST['password'])."\r\n"; fwrite ( $fp, $data ); fclose ( $fp ); print "You are now registered!"; } exit; ?> and this is the login: <?php //debug echo $_POST['username']; echo "<br>"; echo $_POST['password']; echo "<br>"; // end debug if (isset ($_POST['submit'])) { $loggedin = FALSE; $fp = fopen ( 'users.txt', 'rb' ); while ($line = fgetcsv($fp,100,",")) { echo $line[0]." ".$line[1]; echo "<br>"; //debug if ( ($line[0] == $_POST['username']) AND ($line[1] == ($_POST['password']) ) ) { $loggedin = TRUE; echo "line 24 <br>"; //debug //break; } } if ($loggedin) { print '<br>Username and Password are correct.'; exit; } else { print '<br>The username and password did not match!'; } } ?> <form action="login.php" method="post"> Username: <input type="text" name="username"> <br /><br /> Password: <input type="password" name="password"> <br /><br /> <input type="submit" name="submit" value="Login"> </form> Edited February 11, 2013 by tbucknall Quote Link to comment https://forums.phpfreaks.com/topic/274351-php-application-using-flat-file/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.