JordanStreet Posted August 12, 2006 Share Posted August 12, 2006 here is my script$password = 'mypass';info = file("members/$username");if($password == $info[1]){ echo "login succes"; }else{ echo "wrong password"; }however no matter what it always returns false Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 12, 2006 Share Posted August 12, 2006 what does the file "members/$username" look like? what are it's contents? Quote Link to comment Share on other sites More sharing options...
mainewoods Posted August 12, 2006 Share Posted August 12, 2006 you're missing a '$' at the beginning of this line:[code]info = file("members/$username");[/code]don't know where you stored your password, but the first line from the file will be the '0' element (not '1') of the array:[code]if($password == $info[0]){[/code]are you storing information in files without file extensions. your code would implie that:[code]info = file("members/$username");[/code]maybe add .txt?[code]$info = file("members/$username.txt");[/code]check whether the file exists:[code]echo (file_exists("members/$username"))? "file exists" : "doesn't exist";[/code] Quote Link to comment Share on other sites More sharing options...
JordanStreet Posted August 12, 2006 Author Share Posted August 12, 2006 okay here is the full code<form action="login.php" method="post">Username:<br/><input type="text" name="username"><br/>Password:<br/><input type="password" name="password"><br/><input type="submit" name="submit" value="Login"></form><?if(isset($_POST['submit'])){ $username = $_POST['username'];$password = $_POST['password'];if(file_exists("members/$username")){$info = file("members/$username");if($password == $info[1]){ echo "login succes"; }else{ echo "wrong password"; }}else{ echo "Username not found please try again.";}}?>and when i submit the form i use Jordan as the username and in the file members/jordan (no file extension) I have my password stored on the second linethe thing is i can echo $info[1] I just cant use it in the if statementhope this clears things up Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 12, 2006 Share Posted August 12, 2006 do a trim on $info[1].You need to remove the newline character from the end, otherwise they won't match.[code]f($password == trim($info[1])){ echo "login succes"; }else{ echo "wrong password"; }[/code] Quote Link to comment Share on other sites More sharing options...
JordanStreet Posted August 12, 2006 Author Share Posted August 12, 2006 :) worked like a charm. Thanks a bunch man. However im looking in the php manual about the trim function and im a lil confused because as far as I know there was no what space in my text file. Could you maybe explain this a little more ? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 12, 2006 Share Posted August 12, 2006 It removes white space and newline characters...[quote] This function returns a string with whitespace stripped from the beginning and end of str. Without the second parameter, trim() will strip these characters: * " " (ASCII 32 (0x20)), an ordinary space. * "\t" (ASCII 9 (0x09)), a tab. * "\n" (ASCII 10 (0x0A)), a new line (line feed). * "\r" (ASCII 13 (0x0D)), a carriage return. * "\0" (ASCII 0 (0x00)), the NUL-byte. * "\x0B" (ASCII 11 (0x0B)), a vertical tab. [/quote]The one's that pertain to your situation are the \n and \r Quote Link to comment Share on other sites More sharing options...
JordanStreet Posted August 12, 2006 Author Share Posted August 12, 2006 yeah i echoed them again and noticed that there is a white space after the non trimed one. Yeah this deff brings some insight. Thanks again ;D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.