View previous topic :: View next topic |
Author |
Message |
mrpaul -
Joined: 23 Sep 2005 Posts: 18
|
Posted: Tue Oct 25, 2005 12:04 am Post subject: Text file database |
|
|
Hi, i'm trying to creat a text file that hold's data, now that easy but i also want a php script to read this text file and take actions acording to the data.
The text fiel would hold usernames and passwords and the php file would see if the posted usernam and password match with the usernames and passwords in the text file.
Problem is i dont no how to code this,
i have got a ruff script at hand of how it would go
Code: |
<?php
$database = "database.txt";
$openfile = fopen ( $database, "r" );
$read = fread ( $openfile );
$username = $_POST['username'];
$password = $_POST['password'];
If preg_match ( ( $username $password , $read ) )
{ include"logedin.php"; }
else
{
echo ("Sorry username and password did not match or dont exist");
?>
|
The text file would be set out like this,
username password
antoher user password
admin passowrd
mruser password
I'm pritty sure this wouldent work so what would be the correct code? |
|
Back to top |
|
 |
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Tue Oct 25, 2005 4:29 am Post subject: |
|
|
As I just said somewhere, I'm half asleep, so don't mind my errors or whatever.
Code: | function loggedin() {
$contents = explode("\n", implode("", file("database.txt")));
if (!is_array($contents))
return false;
foreach($contents as $thisline_key => $thisline_data) {
if ($thisline_data == $_POST['username']." ".$_POST['password'])
return true;
}
return false;
}
if (loggedin())
include("loggedin.php");
else echo "Sorry username and password did not match or dont exist."; |
_________________
 |
|
Back to top |
 |
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|