• 0

Bug in PHP?


Question

Hi, I'm creating a forum with Text File login system and I have all the datas saved like this:

 

[data]

Pass = asd

Email = asd@asd

...

[end]

 

So in my PHP code I did this:

 

$userlist = file("$username.ini");

$checkline = $userlist[1]; //as I need to check the password so this means line 2

$checkpass = explode(" ", $checkline);

if(strcmp($password, $checkpass[2]) == 0) //$checkpass[2] means the asd part

{

echo "Welcome back $username";

}

else

{

echo "Incorrect Password";

}

 

So when I type asd in the field it shows me Incorrect Password.

But when I changed the $checkpass[2] to $checkpass[0] //$checkpass[0] means the Password part

and I type Password in the field its works perfectly..

I want to ask if there is something wrong? or explode does not work with the las word?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

You're only exploding 2 items as per:

$checkpass = explode(" ", $checkline);

It's a ZERO based index, as you said yourself you know that $checkpass[0] returns the first item in your data, so why pray-tell are you skipping the number 1 for the second item in the list and going for 2 which would be the third item in a zero-based index collection?

Link to comment
Share on other sites

  • 0

You're only exploding 2 items as per:

$checkpass = explode(" ", $checkline);

It's a ZERO based index, as you said yourself you know that $checkpass[0] returns the first item in your data, so why pray-tell are you skipping the number 1 for the second item in the list and going for 2 which would be the third item in a zero-based index collection?

 

$checkpass[0] = 'Email';

$checkpass[1] = '=';

$checkpass[2] = 'asd';

He's correct to be using 2 as the index.

 

OP, where are you setting the value of $password? This isn't shown in the php code you provided above.

Link to comment
Share on other sites

This topic is now closed to further replies.