Jump to content

Recommended Posts

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 by tbucknall
Link to comment
https://forums.phpfreaks.com/topic/274351-php-application-using-flat-file/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.