TheJoey Posted October 12, 2009 Share Posted October 12, 2009 <?php session_start(); $usernamematch = $_POST['username']; $passwordmatch = $_POST['password']; $fp = fopen("registrationinfo/info.txt","a"); $array = explode(':', $fp); $username = trim($array[0]); //user-name $password = trim($array[2]); //password if ($username == $usernamematch && $password == $passwordmatch) { $_SESSION['loginsuccessfull'] = true; header('location indexsuccessfull.php'); } else { header('location wronginfo.php'); } ?> but at the moment its doing nothing just a blank page. im not sure how to work with txt files this way. any help is much appricatied Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted October 12, 2009 Share Posted October 12, 2009 You seem to assume that opening a file is the same as reading it. $array = explode(':', $fp); should be something like: $fileData = fread($fp,filesize("registrationinfo/info.txt")); $array = explode(':', $fileData); Quote Link to comment Share on other sites More sharing options...
TheJoey Posted October 12, 2009 Author Share Posted October 12, 2009 Should i remove the $fp = $fp = fopen("registrationinfo/info.txt","a"); ?? well with the modified code i still didnt get anything. <?php session_start(); $usernamematch = $_POST['username']; $passwordmatch = $_POST['password']; $fp = fopen("registrationinfo/info.txt","a"); $fileData = fread($fp,filesize("registrationinfo/info.txt")); $array = explode(':', $fileData); $username = trim($array[0]); //user-name $password = trim($array[1]); //password if ($username == $usernamematch & $password == $passwordmatch) { $_SESSION['loginsuccessfull'] = true; header('location indexsuccessfull.php'); } else { header('location wronginfo.php'); } ?> Quote Link to comment Share on other sites More sharing options...
GKWelding Posted October 12, 2009 Share Posted October 12, 2009 $fp = fopen("registrationinfo/info.txt","a+"); $fileData = fread($fp,filesize("registrationinfo/info.txt")); fclose($file); $array = explode(':', $fileData); mode a means wrtie only, a+ means read/write. Quote Link to comment Share on other sites More sharing options...
GKWelding Posted October 12, 2009 Share Posted October 12, 2009 also, can I point out that because you're using a file with the extension .txt if somebody gueses the location and name of this file then they will be able to see all of your usernames/password in their browser in plain text, not very secure at all. you'll need a htaccess file in the same directory with the following in it (Google htaccess): IndexIgnore *.txt Quote Link to comment Share on other sites More sharing options...
TheJoey Posted October 12, 2009 Author Share Posted October 12, 2009 Warning: fclose() expects parameter 1 to be resource, null given on line 8 Warning: Cannot modify header information - headers already sent by on line 18 running into a few error Quote Link to comment Share on other sites More sharing options...
GKWelding Posted October 12, 2009 Share Posted October 12, 2009 dammit, my fauly, fclose($file); should be fclose($fp); and read the post stickied at the top of this form for headers already sent. Quote Link to comment Share on other sites More sharing options...
GKWelding Posted October 12, 2009 Share Posted October 12, 2009 however, the headers error is because you're trying to modify header info after an error has been output to the screen. fix the error and the headers error will go. Quote Link to comment Share on other sites More sharing options...
TheJoey Posted October 12, 2009 Author Share Posted October 12, 2009 im still getting a a empty page... ive tried fixing it with soloution's and i keep changing it and its always a blank page heres the complete code. <?php session_start(); $usernamematch = $_POST['username']; $passwordmatch = $_POST['password']; $fp = fopen("registrationinfo/info.txt","a+"); $fileData = fread($fp,filesize("registrationinfo/info.txt")); fclose($fp); $array = explode(':', $fileData); $username = trim($array[0]); //user-name $password = trim($array[1]); //password if ($username == $usernamematch & $password == $passwordmatch) { $_SESSION['loginsuccessfull'] = true; header('location indexsuccessfull.php'); } else { header('location wronginfo.php'); } ?> Quote Link to comment Share on other sites More sharing options...
TheJoey Posted October 12, 2009 Author Share Posted October 12, 2009 i fixed the blank page stupid error on my behalf location url instead of being location: url im always getting wronginfo.php though now. Quote Link to comment Share on other sites More sharing options...
GKWelding Posted October 12, 2009 Share Posted October 12, 2009 ok, do me a favour, change to the following: $fp = fopen("registrationinfo/info.txt","a+"); $fileData = fread($fp,filesize("registrationinfo/info.txt")); print_r($fileData); fclose($fp); You will get the headers error again but ignore that and paste the printed data to this thread. Quote Link to comment Share on other sites More sharing options...
TheJoey Posted October 12, 2009 Author Share Posted October 12, 2009 test1:test2:test3:test4:test5:test6 test1 being my username test2 being my password Quote Link to comment Share on other sites More sharing options...
GKWelding Posted October 12, 2009 Share Posted October 12, 2009 ok, now change the following section to: $username = trim($array[0]); //user-name $password = trim($array[1]); //password print_r($username); print_r($password); and check that matches what you're typing in to login. Quote Link to comment Share on other sites More sharing options...
TheJoey Posted October 12, 2009 Author Share Posted October 12, 2009 test1:test2:test3:test4:test5:test6 test1test2 is what was displayed and that is exactly what im typing in even copied pasted to make sure Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted October 12, 2009 Share Posted October 12, 2009 if ($username == $usernamematch && $password == $passwordmatch) Quote Link to comment Share on other sites More sharing options...
TheJoey Posted October 12, 2009 Author Share Posted October 12, 2009 if ($username == $usernamematch && $password == $passwordmatch) i was thinking thats where the problem lies, and i did try that. Im still getting Whooops error meaning im being directed to the wronginfo.php page. Quote Link to comment Share on other sites More sharing options...
GKWelding Posted October 12, 2009 Share Posted October 12, 2009 do print_r on all 4 variables within the IF statement, make sure they are what you are expecting. if not then that's your problem. Quote Link to comment Share on other sites More sharing options...
TheJoey Posted October 12, 2009 Author Share Posted October 12, 2009 print_r($username); print_r($usernamematch); print_r($password); print_r($passwordmatch); wont work for me. could it be that $usernamematch == $username ? insted of $username == $usernamematch Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted October 12, 2009 Share Posted October 12, 2009 print_r($username); print_r($usernamematch); print_r($password); print_r($passwordmatch); wont work for me. What do you mean "wont work for me"? What are you getting? could it be that $usernamematch == $username ? insted of $username == $usernamematch By the rules of logic, A = B is the same as B = A. So $usernamematch == $username and $username == $usernamematch are identical Quote Link to comment Share on other sites More sharing options...
TheJoey Posted October 12, 2009 Author Share Posted October 12, 2009 test1test2 i get that for all 4 variables. could it be that it isnt retrieveing the information from the file correctly? Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted October 12, 2009 Share Posted October 12, 2009 Modify print_r($username); print_r($usernamematch); print_r($password); print_r($passwordmatch); to echo '$username='; print_r($username); echo '<br />$usernamematch='; print_r($usernamematch); echo '<br />$password='; print_r($password); echo '<br />$passwordmatch='; print_r($passwordmatch); echo '<br />'; That way, you can see whether it's the values you're reading from the file that are wrong, or if it's the $_POST data that isn't right Quote Link to comment Share on other sites More sharing options...
TheJoey Posted October 12, 2009 Author Share Posted October 12, 2009 $username=test1 $usernamematch=test1 $password=test2 $passwordmatch=test2 Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted October 12, 2009 Share Posted October 12, 2009 so its $_POST that is causing the issues... ill be having a look. $_POST['Variable'] is the correct way to post isnt it? It is the correct way, and remember that the Variable is case-sensitive... it must match the name in your html form exactly. Try putting print_r($_POST) at the top of your script. Quote Link to comment Share on other sites More sharing options...
TheJoey Posted October 12, 2009 Author Share Posted October 12, 2009 Ive worked it out... after all that the reason it wasnt working was because of all the r_prints & i had to change the values within post. All working now thanks for that guys. 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.