File contents & string aren't matching

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
matt1234
Forum Commoner
Posts: 44
Joined: Wed Nov 26, 2008 9:43 pm

File contents & string aren't matching

Post by matt1234 »

Code: Select all

$1 = file_get_contents("/path/to/whatever.txt");
    $2 = file_get_contents("/path/to/whatever2.txt");
    $user = md5($_POST['1']);
    $pwd = md5($_POST['2']);
    if (($user == $1) AND ($pwd == $2)) { echo 'Logged in'; die(); }
    else { echo 'Not logged in'; die(); }
These aren't equaling each other. I've echo printed all values and they look like the values should match.
And I'm pretty sure it wouldn't be including an EOL or EOF character at the end of $1 and $2, right?
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: File contents & string aren't matching

Post by Eric! »

Something must be different. Have you checked the string lengths?
matt1234
Forum Commoner
Posts: 44
Joined: Wed Nov 26, 2008 9:43 pm

Re: File contents & string aren't matching

Post by matt1234 »

trim() function worked. Must have been putting the end of file character into the string...
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: File contents & string aren't matching

Post by Eric! »

Some browsers append a CR or LN text string in the form variable. I think firefox does this.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: File contents & string aren't matching

Post by Eric! »

Well, I don't remember the details (this was some time ago) but before I inserted a call to trim() had had several firefox users having login problems that I traced to their string submissions. I don't remember what firefox version they had or what character was being added...sorry. It is a standard input type=text, though.
Post Reply