Text file database

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
mrpaul
-


Joined: 23 Sep 2005
Posts: 18

PostPosted: Tue Oct 25, 2005 12:04 am    Post subject: Text file database Reply with quote

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 View user's profile Send private message
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Tue Oct 25, 2005 4:29 am    Post subject: Reply with quote

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 View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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


Powered by phpBB phpBB Group