Jump to content

flat file login


Grant132

Recommended Posts

Hey..

 

I've been playing with this script for a few hours this morning and i can't find whats wrong with it...

 

<?php
session_start();
$user = $_POST['username'];
$pass = $_POST['password'];

$details = file("flat_file_database.php");

foreach($details as $key => $Val)
{
$data[$key] = explode("||", $Val);
}
for($k = 0; $k < sizeof($details); $k++)
{
$u = $data[$k][0];
$p = $data[$k][1];

if($user == $u && $pass == $p)
{
      $_SESSION['user'] = $user;
      $_SESSION['logged'] = "yes";
      $_SESSION['test'] = "1";
      
      include("news.php");
      
      }else{

      print "username or pass was incorrect";
   
     }
}
?>

 

When i go to login gives me the username or pass was incorrect error, even though the details i use are exact from the flat file db.

If anyone sees where ive gone wrong could you please let me know =D

 

Thanks in advanced,

Grant

Link to comment
https://forums.phpfreaks.com/topic/39981-flat-file-login/
Share on other sites

hmm i tried taking out the "&& $pass == $p and it worked perfectly:

 

<?php
session_start();
$user = $_POST['username'];
$pass = $_POST['password'];

$details = file("db.php");

foreach($details as $key => $Val)
{
$data[$key] = explode("||", $Val);
}
for($k = 0; $k < 1; $k++)
{
$u = $data[$k][0];
$p = $data[$k][1];

if($user == $u)
{
      $_SESSION['user'] = $user;
      $_SESSION['pass'] = $pass;
      $_SESSION['logged'] = "yes";
      $_SESSION['test'] = "1";
      
      include("news.php");
      
      }else{

      print "username or pass was incorrect";
   
     }
}
?>

 

does that help at all?

Link to comment
https://forums.phpfreaks.com/topic/39981-flat-file-login/#findComment-193394
Share on other sites

ok scrap that...

 

<?php
session_start();
$user = $_POST['username'];
$pass = $_POST['password'];

$details = file("db.php");

foreach($details as $key => $Val)
{
$data[$key] = explode("||", $Val);
}
for($k = 0; $k < 1; $k++)
{
$u = $data[$k][0];
$p = $data[$k][1];

if($user == $u && $pass == $p)
{
      $_SESSION['user'] = $user;
      $_SESSION['pass'] = $pass;
      $_SESSION['logged'] = "yes";
      $_SESSION['test'] = "1";
      
      include("news.php");
      
      }else{

      print "username or pass was incorrect";
   
     }
}
?>

 

and

user1||password||
user1||pass||

 

(the extra || on the end)

 

that works however it only works for the first combination..

 

Link to comment
https://forums.phpfreaks.com/topic/39981-flat-file-login/#findComment-193396
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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