• 0

PHP Login Form with Text File


Question

Hello guys, I'm wondering if i can connect my users with text files.

My text file looks like this:

[data]

Password = asd

Email = asd@asd

.

.

.

...

[end]

 

So I have my code like this:

$username = $_GET['username'];

$password = $_GET['password'];

bla. bla. bla

 

But I don't know how to do it to check if the password inputted is the same as the one in the text file.

 

Can someone help me with this code?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

you would need something like this

$userN = $_GET['username'];
$passW = $_GET['password'];
$userlist = file ('users.txt');
$checkUser =$userlist[0];

if (isset($_POST['login']))
{
if ($userN == $userlist)
{
    echo "<br> Hi $user you have been logged in. <br>";
}
else
{
echo "<br> You have entered the wrong username or password. Please try again. <br>";
}
}
Link to comment
Share on other sites

  • 0

Hi Haggis, Thank for your reply.

 

Why I use if($password === $checkpass) it always fail? even if i typed the correct one?

 

I also tried this:

 

if(!success)

{

echo "$password is not equal to $checkpass";

}

 

and it shows like the same things:

 

asd is not equal to asd

 

WHY?

Link to comment
Share on other sites

  • 0

Hi Haggis, Thank for your reply.

 

Why I use if($password === $checkpass) it always fail? even if i typed the correct one?

 

I also tried this:

 

if(!success)

{

echo "$password is not equal to $checkpass";

}

 

and it shows like the same things:

 

asd is not equal to asd

 

WHY?

There's probably whitespace.  Use trim($checkpass).

Link to comment
Share on other sites

This topic is now closed to further replies.